根据GridView72变的方法,对表格的第一列进行序号重新改写,就是按顺序,1,2,3,4,
代码如下: protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
////鼠标经过时,行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
////鼠标移出时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'"); ////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//} }
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}使用也正常,完全符合要求。
但是我有个页面上使用了三个GridView,就不行了,第一列全部为空白,什么也没有,
反复试了好多回,都没有用。
大家能告诉我是怎么回事吗?多谢!
代码如下: protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
////鼠标经过时,行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
////鼠标移出时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'"); ////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//} }
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}使用也正常,完全符合要求。
但是我有个页面上使用了三个GridView,就不行了,第一列全部为空白,什么也没有,
反复试了好多回,都没有用。
大家能告诉我是怎么回事吗?多谢!
解决方案 »
- 高分求 自助建站系统思路。 可拖拽,人性化等。
- ado.net查询简单问题
- vs2008 调试自动退出
- .Net通过模版生成Word 和Excel下载 部署到IIS报错
- 请教各位一个棘手的问题。大家一定要帮我看看啊。我已经搞了一下午了。还是没搞定啊。
- 如何让GridView的单元格按照字段的长度自动调整宽度??
- 有关URL重写的问题
- 再问:我想用Response.WriteFile();防盗链播放MP3,为什么每次运行都弹出提示打开或者保存,而不能直接播放
- 数据修改后如何提示数据未保存,急!!!!
- 如何从datagrid中取出被编辑字段的内容(还没有保存)
- 关于DIV 和 Form
- gridview的DataFormatString4位小数,是0不显示,不是0全显示(急!)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = (e.Row.DataItemIndex + 1).ToString();
}
}
为什么就这个不行,
吧cells【0】该成cells【1】则第二列全部为空白,
调试的时候,id是有值的为1,2,。。
<ItemTemplate>
<%#Container.DataItemIndex +1 %>
</ItemTemplate>
</asp:TemplateField>后台不用去写行号了