gridview 怎么可以访问 某一行的某一列值

冷眼1983 2009-09-07 10:52:06
问个问题 ,gridview 怎么可以访问 某一行的某一列值

在datagrid中可以用 datagfid.item[].cell[].text
但不知道 gridview中 RowCommand 如何获得

protected void DataPolice_RowCommand(object sender, GridViewCommandEventArgs e)
{
string f_userid = DataPolice.Rows[DataPolice.SelectedIndex].Cells[0].Text.ToString();
}

报错,
[ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index]



求高手帮忙解决



...全文
228 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
nocallstle 2009-09-07
  • 打赏
  • 举报
回复
  if (e.Row.RowType == DataControlRowType.DataRow) 

要判断是不是为数据行
冷眼1983 2009-09-07
  • 打赏
  • 举报
回复
谢谢,各位的帮忙,解决了,谢谢。谢谢。现在结帖
我家有奥特曼 2009-09-07
  • 打赏
  • 举报
回复

//取某一行某一列的值
string strtemp = gridview1.Rows[行索引].Cells[列索引].Text;
//取某一行某一列中控件的值
控件类型 ctrtemp = gridview1.Rows[行索引].Cells[列索引].FindControl("控件名") as 控件类型;
string strtemp=strtemp.Text;
  • 打赏
  • 举报
回复
rowcommand方法

int id = Convert.ToInt32(e.CommandArgument);
GridViewRow drv = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
int index = drv.RowIndex;
TextBox txtName = (TextBox)GridView1.Rows[index].FindControl("txtName");
txtname.text就是你要的值

我的这一列是放的textbox,换成你自己的。
laobie1004 2009-09-07
  • 打赏
  • 举报
回复
帮顶!
mao924 2009-09-07
  • 打赏
  • 举报
回复
帮顶
ivws_19 2009-09-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 kiss_majun 的回复:]
没有 E.ROW这个属性

引用 3 楼 jackie545cs 的回复:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string sss = e.Row.Cells[0].Text;
    }

[/Quote]
rowcommand里是没有这属性的,用e.CommandArgument
zjybushiren88888 2009-09-07
  • 打赏
  • 举报
回复
protected void ProGridView_RowDataBound(object sender, GridViewRowEventArgs e) 
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//伪代码
}
}
冷眼1983 2009-09-07
  • 打赏
  • 举报
回复

没有 E.ROW这个属性

[Quote=引用 3 楼 jackie545cs 的回复:]
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string sss = e.Row.Cells[0].Text;
    }
[/Quote]
昕颖 2009-09-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wxd_860825 的回复:]
访问某一行的列值
string stupdatetext = ProGridView.Rows[e.RowIndex].Cells[0].Text;
访问某一行改变的列值
stupdatetext = ((TextBox)(ProGridView.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
下面是我的例子,你参考参考
//设定列宽
    protected void ProGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Attributes.Add("style", "display:none;");
        e.Row.Cells[1].Attributes.Add("style", "display:none;");
        if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate) || e.Row.RowState == DataControlRowState.Edit)
        {
            for (int i = 3; i < ProGridView.Columns.Count - 1; i++)
            {
                TextBox txt = (TextBox)e.Row.Cells[i].Controls[0];
                txt.Width = Unit.Pixel(50);
            }
        }
       
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C9D3E2',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            e.Row.Attributes["style"] = "Cursor:pointer";
        }
[/Quote]这个可以。。。谢谢分享
ivws_19 2009-09-07
  • 打赏
  • 举报
回复
string f_userid = DataPolice.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text.ToString();
wxd_860825 2009-09-07
  • 打赏
  • 举报
回复
访问某一行的列值
string stupdatetext = ProGridView.Rows[e.RowIndex].Cells[0].Text;
访问某一行改变的列值
stupdatetext = ((TextBox)(ProGridView.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
下面是我的例子,你参考参考
//设定列宽
protected void ProGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Attributes.Add("style", "display:none;");
e.Row.Cells[1].Attributes.Add("style", "display:none;");
if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate) || e.Row.RowState == DataControlRowState.Edit)
{
for (int i = 3; i < ProGridView.Columns.Count - 1; i++)
{
TextBox txt = (TextBox)e.Row.Cells[i].Controls[0];
txt.Width = Unit.Pixel(50);
}
}

if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C9D3E2',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
e.Row.Attributes["style"] = "Cursor:pointer";
}
jackie545cs 2009-09-07
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string sss = e.Row.Cells[0].Text;
}
wosizy 2009-09-07
  • 打赏
  • 举报
回复
protected void grv_OutInter_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HtmlInputButton btn_ButtonT = (HtmlInputButton)e.Row.Cells[9].FindControl("btn_Opt");
string StatusNM = ((Label)e.Row.Cells[7].FindControl("lbl_StatusNM")).Text;
if (StatusNM == append)
{
btn_ButtonT.Visible = false;
}
else
{
btn_ButtonT.Visible = true;
}
}
}
这是我用的 给你一个列子 你看看改下
randomfeel 2009-09-07
  • 打赏
  • 举报
回复
断点看看 DataPolice.SelectedIndex 的值 和 DataPolice.Rows.Count 的值
gudujianxiao 2009-09-07
  • 打赏
  • 举报
回复
学习学习!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧