Skip to main content

Posts

Showing posts from January, 2012

AutoNumber Column or Auto Number in GridView or DataList ASP.NET

Several times we need to display Auto Number or serial number for displaying records in gridview or other similar controls in ASp.NET. We can add AutoNumber column by using Container.DataItemIndex property in html markup of the Gridview. Here's the sample html markup for the page < title > Auto Number Cloumn in GridView </ title > </ head > < body > < form id ="form1" runat ="server" > < asp:GridView ID ="GridView1" runat ="server" AllowPaging ="True" AutoGenerateColumns ="False" DataSourceID ="SqlDataSource1" PageSize ="6" AlternatingRowStyle-BackColor ="#006699" AlternatingRowStyle-ForeColor ="#FFFFFF" > < Columns > < asp:TemplateField HeaderText ="Serial Number" > < ItemTemplate > <% # Contai

Running Total In Gridview Footer in ASP.NET C# VB.NET

In this example i am going to demonstrate how to display running total in footer row or footer template of GridView in ASP.NET using C# and VB.NET. This method works with paging enabled gridview as well. For demo purpose gridview is populated using sqldatasource having table with columns ID ,Name,Amount I m showing total of amount column is gridview footer. for this we need to sum the the column in RowDataBound Even of Gridiew Html source of gridview is < asp:GridView ID ="GridView1" runat ="server" AutoGenerateColumns ="False" DataKeyNames ="ID" DataSourceID ="SqlDataSource1" OnRowDataBound ="GridView1_RowDataBound" ShowFooter ="True" AllowPaging ="True" PageSize ="5" BackColor ="#ffffff" BorderColor ="AliceBlue" BorderStyle ="No

Merge GridView Cells Or Columns in Row ASP.NET C# VB.NET

In this example i am going to describe how to merge GridView cells or Columns in gridview rows containing same data or content using C# and VB.NET in ASP.NET For this i m using DataBound Event of gridview, counting total rows and then checking each cells value against value of same cell in previous row and then setting the RowSpan of cells. For this i have created a table containing Counties ,states and respective cities and country and state cells / columns are merged in rows having same country or states. For knowing how to merge Gridview headers read article below Merging GridView Header Columns or multiple Headers You would also like to read Hide GridView Columns In Normal Mode and Visible In Edit Running Total In Gridview Footer in ASP.NET C# VB.NET Html source of the page look like this < asp:GridView ID ="GridView1" runat ="server" AutoGenerateColumns ="False" BorderStyle ="

Numeric Number Only TextBox JavaScript RegularExpression Validator

Numeric or Number Only TextBox Using JavaScript or RegularExpressionValidator. In this example i am going to decsribe how create Numeric or Number only textbox using javascript or regular expression Validator which accept only numbers in asp.net web page. 1. Number only textbox using javascript. Go to html source of aspx page and write below mentioned script in head section of page. 1 <script type= "text/javascript" > 2 function numberOnlyExample() 3 { 4      if (( event .keyCode < 48) || ( event .keyCode > 57)) 5      return false ; 6 } 7 </script> Call this function in onKeyPress event of textbox. Write this code in html source of textbox. < asp:TextBox ID ="TextBox2" runat ="server" onKeyPress ="return numberOnlyExample();" > </ asp:TextBox > We can also do this programmetically in code behind like this. on Page_Load event of page add