我要在这里加以个序号 head1 head2 head3
1 1 2 3
2 1 2 3
3 1 2 3
4 1 2 3
5 1 2 3如何实现?
1 1 2 3
2 1 2 3
3 1 2 3
4 1 2 3
5 1 2 3如何实现?
解决方案 »
- 如何给一个gridview里面添加radiobutton并且在选择的时候只能选择一个?急!急!急!急!
- 使用 DownloadString(url) 下载的资源是乱码
- 文章列表的分页方案(生成静态页面方式)
- GridView中使用HyperLink传递2个参数的问题,求一个更好的解决方法
- 关于asp.net读取word文档内容是否雷同
- Linq查询,返回一个值,类似ExecuteScalar
- 谁能告诉我Web.config自定义配置节 的一些疑惑
- asp.net 里有没有 记录指针 类似的东西 可以在内存里存入一张表
- 字段为char型,如何再sql where 里判断他为空, isnot null 好像不行
- DataGrid的分页问题?
- 请注意,菜鸟遇到难题了,请大侠门出手相救
- 希望版主能帮忙解决一下
<itemtemplate>
<%# Container.ItemIndex + 1%>
</itemtemplate>
</asp:templatecolumn>
DataColumn workColumn = workTable.Columns.Add("ID", typeof(Int32));
workColumn.AutoIncrement = true;
workColumn.AutoIncrementSeed = 1;
workColumn.AutoIncrementStep = 1;.............
DataGrid1.DataSource=workTable;
DataGrid1.DataBind();//第三种:
//在page 类中方一个
private int RowCount =0;
//在datagrid的ItemDataBound里边这样放:
if(e.Item.ItemType == ListItemType.Header)
{
RowCount =0;
}
else if(e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternateItem)
{
RowCount ++;
e.Item.Cells[0].Text= RowCount.Tostring();
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.item.Cells[0].Text = "共"+ RowCount.ToString();
}//第四种:
private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int num = e.Item.ItemIndex + 1;
e.Item.Cells[0].Text = num.ToString();
}
}
也可以先在数据库中,加字段行号,,然后用datagrid绑定,在用下面的模板
<asp:templatecolumn ... >
<itemtemplate>
td align="left"><a href="#" onclick='<%# DataBinder.Eval(container.dataitem,"id","javascript:window.open(""reply.aspx?id={0}"",""_blank"",""width=420 , height=510"");")%>'><font color="#3300FF"><%#container.dataitem("title")%></a></font></td>
</itemtemplate>
</asp:templatecolumn>
And I have two stars now!
Container.ItemIndex is not a field in a database. It's only the index of the line. So you can use it even if you doesn't get data from a database.
听到你这么说我感到很抱歉。楼主的这个问题已经不是新问题了,但我自己就回答过n个类似的问题,因此答案早就总结出来了,我所需要做的只是找一下我以前的帖子,然后copy / paste,速度当然比你快了。
e.item.index,这个可以得到这行关键字的值....
你给的代码中用到e.Item.Index了吗?
你为什么说“那样不可以,因为他的数据库没有行号这个字段,所以datagrid控件没法指定keyfield这个字段,所以itemindex值没法直接获得”?