Reputation: 1
My code is like this : Now I have now idea how to get column name of selected row
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 !!";
}
}
}
Upvotes: 0
Views: 2135
Reputation: 1007
It can be possible through DataKeyNames and Normal method also
1) 'e' as Commandargument
int index = Convert.ToInt32(e.CommandArgument); string request = gvRequests.Rows[index].Cells[4].Text.ToString();
2) GridViewRow selectedRow = gvRequests.Rows[index]; string Id = gvRequests.DataKeys[index].Value.ToString().Trim();
string headerText=gvProductList.HeaderRow.Cells[1].Text;
protected void gvCustomers_RowDataBound(object sender, 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 + ");"
}
}... You can try this... method in your own way
Enjoy... ..
Upvotes: 0
Reputation: 4221
Why not create an object of the selected row and work with it from there?
i.e.
var selectedRow = (TYPE)gridViewName.GetFocusedRow();
You could then use the selectedRow object and call any properties belonging to it i.e. var name = selectedRow.Name
Upvotes: 0