gridview中第一列想实现1,2,3....序号方式应怎么办 gridview中第一列想实现1,2,3....序号方式应怎么办 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 双击GridView的OnRowDataBound事件; 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { //如果是绑定数据行 if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowIndex != -1) { int id = e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } } 注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。 <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <HeaderTemplate> 序号 </HeaderTemplate> <ItemTemplate> <%#Container.DataItemIndex+1 %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:TemplateColumn> <ItemTemplate> <%# Container.RowIndex+1 %> </ItemTemplate></asp:TemplateColumn> <asp:TemplateField HeaderText="编号"><itemtemplate><%# Container.DataItemIndex + 1%></itemtemplate><itemstyle horizontalalign="Center" width="80px" /></asp:TemplateField>试试 编辑 定义一个lable Text='<%# Container.ItemIndex%> <asp:GridView ID="gridList" runat="server" PageSize="5" AutoGenerateColumns="false" AllowPaging="true"> <Columns> <asp:TemplateField> <ItemTemplate> <%#((GridViewRow)Container).RowIndex + 1 + gridList.PageIndex * gridList.PageSize%> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="...." /> <asp:BoundField DataField="...." /> </Columns> </asp:GridView> GridView中:<%#Eval(Container.dataitemindex)%>Reapter中:<%#Eval(Container.itemindex)%> 自定义列在rowdatabound的时候手动填?或者在数据源里用临时表加个标识列,但这种方法对排序后仍要求自定义增长列的做法不适合。 <%#Container.DataItemIndex+1 %> 唉 这在DataGrid还是正解 在GridView上可就不一样了 应该得用到缓存么? .求一个规范的开源实例. 一个json问题 使用验证控件脚本出错 刚入门想模仿一个网站做做,请各位大侠指点哪个网站比较合适 OpenFlashChart 运行后自动消失 问:在导入Excel的时候能不能直接打开,而不要提示是打开还是保存? asp.net中如何用键盘响应事件啊(比如说按enter键) word 域显示图片 设置IHttpHandler 所有类型,结果只有.aspx 进入处理 关于AspNetPager与PagedDataSource配合分页的问题 gridview中合计一列的和
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
} }
注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。
<Columns>
<asp:TemplateField>
<HeaderTemplate>
序号
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<ItemTemplate>
<%# Container.RowIndex+1 %>
</ItemTemplate>
</asp:TemplateColumn>
<itemtemplate><%# Container.DataItemIndex + 1%></itemtemplate>
<itemstyle horizontalalign="Center" width="80px" />
</asp:TemplateField>
试试
<Columns>
<asp:TemplateField>
<ItemTemplate> <%#((GridViewRow)Container).RowIndex + 1 + gridList.PageIndex * gridList.PageSize%> </ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="...." />
<asp:BoundField DataField="...." />
</Columns>
</asp:GridView>
<%#Eval(Container.dataitemindex)%>Reapter中:
<%#Eval(Container.itemindex)%>