"Code, Beer and Music ~ my way of being a programmer"
This example shows how to select ListItems in the ListBox based from the TextBox values using JavaScript. Here’s the code block below. <html xmlns="http://www.w3.org/19... > <head id="Head1" runat="server"> <title>Demo</title... </head> <script type="text/javascript" language="javascript"> function SearchList() { var l = document.getElementById('&l... ListBox1.ClientID %>'); var tb = document.getElementById('&l... TextBox1.ClientID %>'); if(tb.value ......
Overview This demo explains how to create a simple ShoutBox using the ASP.NET MultiLine TextBox. A “ShoutBox” basically allow end users to post commentsin the page. To begin let’s create a WebUserControl and implement our ShoutBox there. Why UserControl? We used WebUserControl so that we can re-use and place the control anywhere in your page by simply dragging it to the WebForm. Step 1: Creating the Database In this demo, I presumed that you already have a basic background on how to create a simple ......
This example shows how to move items between two ListBox. Basically it allows you to add, remove and move multiple list items at a time. To start, let’s set up our GUI. Just for simplicity of this demo, I set up the web form like this: 1: <head runat="server"> 2: <title>Moving ListItems between two ListBox</title> 3: </head> 4: <body> 5: <form id="form1" runat="server"> 6: <div> 7: <table> 8: <tr> 9: <td ><asp:ListBox ID="ListBox1" runat="server" ......
This demo shows on how to add a default Select option in the DropDownList. I decided to write this sample demo because I always encounter this question at the ASP.NET forums. To make this work then you just need to set the property AppendDataBoundItems to TRUE in the DropDownList. Here’s an example for adding a Select option declaratively at the mark up. <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true"... <asp:ListItem Value="-1">Select</as... ......
This example shows how to bind DropDownList, ListBox and CheckBoxList control with data from database using the ADO.NET way. Note that in this demo, I’m using the Northwind database. Now let’s set up the connection string. STEP 1: Setting up the Connection string In your web.config file set up the connection string there as shown below: <connectionStrings> <add name="DBConnection" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirec... Integrated Security=True;User ......
Here’s an example on how to highlight GridView rows on mousover at RowCreated or RowDataBound event of GridView by simply adding an attributes to the row. Here’s the code block: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { string onmouseoverStyle = "this.style.backgroundColor... string onmouseoutStyle = "this.style.backgroundColor... if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmou... onmouseoverStyle); e.Row.Attributes.Add("onmou... ......
By default ASPNETDB will be automatically created under App_data directory in your application if personalization is use for the first time.If you wanted to locate ASPNETDB file in your Own Database (SQL Sevrer 2005) then just simply do the following -Copy the ASPNETDB that is located at the App_data Folder in your Apps and paste it anywhere in your drives.. the after copying -Remove the ASPNETDB in your App_Data folder -Open SqlServer 2005 or Studio Management Express -Right Click on Database Folder ......
This demo describes how to implement multiple delete in GridView using CheckBox control and display a confirmation message upon deletion. Assuming that we have this GridView column mark up below <Columns> <asp:TemplateField> <HeaderTemplate> <asp:Button ID="ButtonDelete" runat="server" Text="Delete" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="CustomerID" ......
This demo describes the different approach to display a confirmation message when deleting a row in GridView and pass the id of the item to the confirmation message. Confirmation means a user is asked first if he/she wanted to delete a record by choosing an option (OK and CANCEL). In this demo, we use the JavaScript confirm function for displaying the confirmation message. Now let’s create our JavaScript confirm function. To do this switch to ASPX source and add the following code block within the ......
This demo is a continuation of my previous example “Binding GridView with Data”. If you are not familiar of binding the GridView the ado.net way then I would suggest looking at my previous example first before you proceed to this example. Basically, this demo describes the basic way to do INSERT, EDIT, UPDATE and DELETE data in ASPNET GridView Control using the ADO.NET way. STEP 1: Creating a DataBase Table In this demo, I presumed that you already have a basic background on how to create a simple ......
This example demonstrates how to populate GridView with data from the database using the ADO.NET way. Before you proceed reading this example be sure that you know the basics of ADO.NET manipulation. If you are not familiar with ADO.NET then I would suggest you to refer at the following link below: ADO.NET Tutorial STEP 1: Setting up the Connection String - Open your Web.config file and set up your connection string like below: <connectionStrings> <add name="MyDBConnection" connectionString="Data ......
Just follow these tutorials below regarding how to implement WebParts in ASP.NET based on different Authentication mode. WEBPART with Windows Authentication WEBPART with Anonymous Users WEBPART with FORM Authentication Good Luck! Technorati Tags: ASP.NET,WebParts ......
This example demonstrates how to access ASP.NET server controls that resides within the TemplateField Column of GridView on Edit Mode. In this example we are using the PreRender event of GridView instead of RowEditing event since we cannot directly access controls at RowEditing event of GridView. See below for example: protected void GridView1_PreRender(object sender, EventArgs e){ if (this.GridView1.EditIndex != -1){ Button b = GridView1.Rows[GridView1.Ed... as Button; ......
This example simulates on how to display a loading message with gif image when the page loads in ASP.NET. <html xmlns="http://www.w3.org/19... ><head id="Head1" runat="server"> <title>Load Wait Message Demo</title></head... type="text/javascript" language="javascript"> if(document.getElementById){ // IE 5 and up, FF var upLevel = true; }else if(document.layers) { // Netscape 4 var ns4 = true; } elseif(document.all) { //IE 4 var ie4 = true; } function ......
This example demonstrates how to print or display the contents of the MultiLine TextBox in a Label Control and retain its line breaks. Basically MultiLine Mode of TextBox uses Environment.NewLine to create a new line. So if you try to display the values of TextBox in a Label Control or print it on the page and retain its position then you can replace the Environment.NewLine with <BR> Tag since Label control doesn't recognized Environment.NewLine. Here's a sample demo below for your reference: ......
This example shows how we are going to set the Height of the MultiLine TextBox automatically when the contents of the TextBox is larger than the size of the TextBox. First thing you need is DON'T set the Height of the TextBox in the mark up (ASPX) and then do the following: C# protected void TextBox1_Load(object sender, EventArgs e){ int charRows = 0; string tbCOntent; int chars = 0; tbCOntent = TextBox1.Text; TextBox1.Columns = 10; chars = tbCOntent.Length; charRows = chars / TextBox1.Columns; int ......
This simple JavaScript function validates the TextBox input that allows only numeric values to be entered. <script type ="text/javascript" language="javascript" > function ValidateText(i) { if(i.value.length>0) { i.value = i.value.replace(/[^\d]+/g, ''); } } </script> In your textbox add the onkeyup event or onkeypress. <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_Tex... onkeyup = "javascript:ValidateText(th... Note: If you wan't ......
This example shows how to limit the number of characters to be typed into the TextBox using JavaScript and display the remaining characters in a Label Control. <script type="text/javascript" language="javascript"> function validatelimit(obj, maxchar) { if(this.id) obj = this; var remaningChar = maxchar - obj.value.length; document.getElementById('&l... Label1.ClientID %>').innerHTML = remaningChar; if( remaningChar <= 0) { obj.value = obj.value.substring(maxchar... alert('Character ......
This example shows how to limit the number of Listitems to be selected in the ListBox control. ASPX <html xmlns="http://www.w3.org/19... ><head runat="server"> <title>Untitled Page</title> <script type="text/javascript" language="javascript"> function GetCurrentItemsSelected(obj) { var o = obj; document.getElementById('&l... HiddenField1.ClientID %>').value = o; } </script></head>... <form id="form1" runat="server"> <asp:ListBox ......
Here's an example (One Way) on how are we going to calculate the time difference between two give time: C# DateTime dFrom; DateTime dTo; string sDateFrom = "11:56:00"; string sDateTo = "12:12:00"; if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo)) { TimeSpan TS = dTo - dFrom; int hour = TS.Hours; int mins = TS.Minutes; int secs = TS.Seconds; string timeDiff = hour.ToString("00") + ":" + mins.ToString("00") + ":" + secs.ToString("00"); Response.Write(timeDiff); ......