如何从Gridview获取选定的值 [英] How to get selected value from Gridview

查看:85
本文介绍了如何从Gridview获取选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个gridview CompanyGv1.i需要获取选定的行值


Hi,

I have a gridview CompanyGv1.i need to get the selected rows value


protected void btncontact_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Company/Contact.aspx?CompanyName=" + CompanyGv1.SelectedRow.Cells[1].Text);
    
    }



出现错误对象引用未设置为对象的实例".
请帮忙.

谢谢.



getting error "Object reference not set to an instance of an object".
please help.

Thanks.

推荐答案

引用此链接将对您有所帮助:

http: //www.dotnetfunda.com/articles/article442-how-to-to-get-the-values-of-selected-row-from-a-gridview-using-aspnet.aspx [
Refer this link it will help you:

http://www.dotnetfunda.com/articles/article442-how-to-get-the-values-of-selected-row-from-a-gridview-using-aspnet.aspx[^]


在RowDataBound事件中添加您的代码.然后,您将获得单元格值.

在RowDataBound事件中添加以下代码.

声明存储行值的变量.

<数据类型> RowVal;
add your code at RowDataBound event. Then you get cell value.

In RowDataBound Event add following code.

declare a variable for store Row value.

<datatype> RowVal;
protected void CompanyGv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
         RowVal = e.Row.Cells[1].Text.ToUpper();
    }
}



然后将此变量传递给您的代码.



And then pass this variable to your code.

protected void btncontact_Click(object sender, EventArgs e)
{
    Response.Redirect("~/Admin/Company/Contact.aspx?CompanyName=" + RowVal );
}




rowcommand事件将帮助您,将命令参数提供给控件(如选择按钮),并获得当前行,这就是获取当前行的值.

如果您有不同的情况,请指定.

一切顺利.
hey

rowcommand event will help u, give commandargument to your control like select button and get the current row thats it just fetch the value of the current row.

if you have different case please specify.

all the best..


这篇关于如何从Gridview获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆