Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Sun, 26-Oct-2014 Authors
All Time Authors
Satyapriyanayak
12160
Vishal@Neeraj
8240
Jayakumars
8120

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

Create auto Generate Serial Number In Gridview

Santosh0683
Posted by Santosh0683 under ASP.NET on 8/29/2010 11:07:46 AM | Points: 40 | Views : 9169 | Status : [Member]

Auto Generate Serial Number In Gridview

The Given code auto generate serial number with page index changing.
Generate Dynamic Serial Number in GridView is coommon task for many programmer
Here i explain it in very simple way
1: Drag GridView in you asp.net web page.
2: Go to Gridview properties and Click on Columns than add Template Column.
3:Code is given below
The Given code auto generate serial number with page index changing.
Generate Dynamic Serial Number in GridView is coommon task for many programmer

Here i explain it in very simple way
1: Drag GridView in you asp.net web page.
2: Go to Gridview properties and Click on Columns than add Template Column.
3:Code is given below

<asp:GridView ID="gv" runat="server" DataKeyNames="Id">

<Columns>
<asp:TemplateField HeaderText="Sr. No">
<ItemTemplate>
<asp:Label ID="lblSrNo" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="EmpName">
<ItemTemplate>
<asp:Label ID="lblEmpName" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="50px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
.cs code
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblSrNo = (Label)e.Row.FindControl("lblSrNo");
lblSrNo.Text = SrNo.ToString();
SrNo++;
int pageNum = gv.PageIndex * gv.PageSize + Sr;
e.Row.Cells[1].Text = pageNum.ToString();
}
}



Santosh Singh
http://aspdotnetcode.blogspot.in/
Found interesting? Add this to:



Comments or Responses

Posted by: Raja on: 8/29/2010 | Level:Starter | Status: [Member] | Points: 10

I think you have missed to declare the SrNo variable in the code snippet. So ideally you should have a page level variable SrNo.

Thanks for the code snippet.

Posted by: Csmaniam on: 8/30/2010 | Level:Starter | Status: [Member] | Points: 10

Instead of putting loop in data source changed event.

use code like this in aspx page

<asp:Label ID="lblSrNo" runat="server" <%Eval(DataBinder.DataItemIndex %>></asp:Label>


Posted by: Suri1319@gmail.com on: 12/27/2011 | Level:Starter | Status: [Member] | Points: 10

hi friends
i want to insert,update data in to the data base through the grid view with button click. and search the data in grid view please send the code details to this id suri1319@gmail.com


Login to post response