本文介绍了在gridview中生成序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在gridview中生成我们自己的序列号?
例如我们在gridview中有10条记录,所以第一列应该代表序列号如1 2 3到10
:叹气:
帮助我
How to generate our own serial number in gridview?
eg we have ten records in gridview so first col should represents serial no Like 1 2 3 to 10
:sigh:
help me
推荐答案
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" ...
2.在你的内部添加TemplateField GridView:
2. Add TemplateField inside your GridView:
<asp:TemplateField HeaderText="Serial number">
<ItemTemplate>
<asp:Label ID="lblSerial" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
3.在代码隐藏中添加此项:
3. Add this in code-behind:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblSerial = (Label)e.Row.FindControl("lblSerial");
lblSerial.Text = ((GridView1.PageIndex * GridView1.PageSize) + e.Row.RowIndex + 1).ToString();
}
}
希望这会有所帮助。:upumbsup:
Hope this helps.:thumbsup:
<asp:TemplateField>
<HeaderTemplate>
Serial No.</HeaderTemplate>
<itemtemplate>
<asp:Label ID="lblSRNO" runat="server" Text='<%#Container.DataItemIndex+1 %>'>
</itemtemplate>
你可以问我任何问题,我会亲自试试....
告诉我之后你做完了....
快乐编码
you can ask me any questions i will try my hand on that....
tell me after you done....
happy coding
这篇关于在gridview中生成序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!