0

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

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 !!";
            }
        }

    }
4

3 回答 3

1

试试这个代码片段;

gv.HeaderRow.Cells[i].Text
于 2013-03-08T09:58:34.590 回答
0

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

IE

var selectedRow = (TYPE)gridViewName.GetFocusedRow();

然后,您可以使用 selectedRow 对象并调用属于它的任何属性,即 var name = selectedRow.Name

于 2013-03-08T07:46:15.770 回答
0

也可以通过 DataKeyNames 和 Normal 方法

1) 'e' 作为命令参数

int index = Convert.ToInt32(e.CommandArgument); 字符串请求 = gvRequests.Rows[index].Cells[4].Text.ToString();

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

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

protected void gvCustomers_RowDataBound(对象发送者,GridViewRowEventArgs e)

{

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

{
   LinkButton lnk = (LinkButton) e.Row.FindControl("lnk");
   Label lblName= (Label) e.Row.FindControl("lblName");                      
   lnk.Attributes.Add("onclick", "getValue(" + lblName.ClientID + ");"
}

}...你可以用你自己的方式尝试这个...方法

享受... ..

于 2013-03-08T10:33:42.127 回答