C# 如何使用c从asp.net中的datagrid中获取选定的列值或名称#

C# 如何使用c从asp.net中的datagrid中获取选定的列值或名称#,c#,asp.net,C#,Asp.net,我的代码是这样的:现在我知道了如何获取所选行的列名 protected void gv_imageslist_RowUpdating(object sender, GridViewUpdateEventArgs e) { string status; string sts; int result; lblerror2.Text = ""; //((label)gv.Rows.FindControl("lbl1")).

我的代码是这样的:现在我知道了如何获取所选行的列名

protected void gv_imageslist_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
        string status;
        string sts;
        int result;
        lblerror2.Text = "";
        //((label)gv.Rows.FindControl("lbl1")).Text;

        string str = gv_imageslist.c

        if (str  == "Status")
        {
            status = ((Label)gv_imageslist.Rows[e.RowIndex].FindControl("lbl_Status")).Text;
            Gm.Gallery_Id = Convert.ToInt32(gv_imageslist.DataKeys[e.RowIndex].Value.ToString());
            if (status == "True")
            {
                Gm.Is_Active = false;
            }
            else
            {
                Gm.Is_Active = true;
            }
            result = Gm.Change_Image_Status();
            if (result == 1)
            {
                Build_ImageGalleryList();
            }
            else
            {
                lblerror2.Visible = true;
                lblerror2.Text = "Unable to Change Status !";
            }
        }
        else
        //------For Checking of cover pic
        {
            sts = ((Label)gv_imageslist.Rows[e.RowIndex].FindControl("lbl_Cover")).Text;
            Gm.Gallery_Id = Convert.ToInt32(gv_imageslist.DataKeys[e.RowIndex].Value.ToString());

            string sp = ((Label)gv_imageslist.Rows[e.RowIndex].FindControl("lbl_category_Id")).Text;
            Gm.Category_Id = Convert.ToInt32 (sp);
            if (sts == "False")
            {
                Gm.Is_Cover = true;
            }
            else
            {
                Gm.Is_Cover = false;
            }
            result = Gm.Change_Gallery_Cover();
            if (result == 1)
            {
                Build_ImageGalleryList();
            }
            else
            {
                lblerror2.Visible = true;
                lblerror2.Text = "Unable To Change Cover Pic !!";
            }
        }

    }

为什么不创建所选行的对象并从中使用它呢

i、 e

然后可以使用selectedRow对象并调用属于它的任何属性
i、 e.var name=selectedRow.name

试试这个代码片段

gv.HeaderRow.Cells[i].Text

也可以通过DataKeyName和普通方法实现

1) “e”作为命令参数

int index=Convert.ToInt32(e.CommandArgument); string request=gvRequests.Rows[index]。单元格[4]。Text.ToString()

2) GridViewRow selectedRow=gvRequests.Rows[索引]; 字符串Id=gvRequests.DataKeys[index].Value.ToString().Trim()


字符串headerText=gvProductList.HeaderRow.Cells[1].Text

受保护的无效数据绑定(对象发送方,GridViewRowEventArgs e)

{

if((e.Row.RowType==DataControlRowType.DataRow))

}。。。你可以试试这个。。。用你自己的方法


享受

有两列。现在我想更新所选列上的特定内容否,它将允许您访问您添加的类型的属性,即查看我在代码中使用的此代码段;var selectedDocumentRow=(CustomDocumentHeader)gvDownloadedDocuments.GetFocusedRow();Process.Start(selectedDocumentRow.CustomDocumentPath);CustomDocumentPath是我在调用的类类型中创建的属性。No。它不起作用了。听着,我有一个6列的网格。在单击行更新时,我有2个条件用于2列。现在我想区分两个条件,因为直到现在,当我点击列时,它执行两个条件。因此,如果您知道,请告诉我如何在asp.netstring headerText=gvProductList.HeaderRow.Cells[1].Text中获取数据网格选定行的列headerText;没错,bt cell[1]给出了第一列名称。我要单击位置的列名您要单击的选定行或单元格的标题吗?
gv.HeaderRow.Cells[i].Text
{
   LinkButton lnk = (LinkButton) e.Row.FindControl("lnk");
   Label lblName= (Label) e.Row.FindControl("lblName");                      
   lnk.Attributes.Add("onclick", "getValue(" + lblName.ClientID + ");"
}