by command name iam getting 'complaintId' and also want to get 'userId' which is other cell..then how?
protected void gridComplaintSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CompVIEW")
{
int row = Convert.ToInt32(e.CommandArgument);
Session["compUid"] = row;
int custId = Convert.ToInt32(gridComplaintSearch.SelectedRow.Cells[4].Text); /*Here throwing an error: Object reference not set to an instance of an object.*/
Response.Write("");
Response.Write("");
}
}
{
if (e.CommandName == "CompVIEW")
{
int row = Convert.ToInt32(e.CommandArgument);
Session["compUid"] = row;
int custId = Convert.ToInt32(gridComplaintSearch.SelectedRow.Cells[4].Text); /*Here throwing an error: Object reference not set to an instance of an object.*/
Response.Write("");
Response.Write("");
}
}

Azaad AbbasPosted Apr 7, 2015, 5:28 AM
http://www.aspdotnet-suresh.com/2012/06/get-multiple-datakeyname-values-from.html
but getting an error at 'string value1 = gvUserInfo.DataKeys[gvrow.RowIndex].Values[0].ToString();' /*at underlined*/
Azaad AbbasPosted Apr 7, 2015, 5:21 AM
protected void gridComplaintSearch_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "CompVIEW")
{
int row = Convert.ToInt32(e.CommandArgument);
Session["compUid"] = row;
Response.Write("");
Response.Write("");
}
}
Khargesh RajputPosted Apr 7, 2015, 5:20 AM
http://www.aspsnippets.com/Articles/How-to-get-Selected-Row-cell-value-from-GridView-in-ASPNet.aspx
http://www.aspdotnet-suresh.com/2014/11/get-selected-row-cell-value-from-gridview-csharp-vbnet.html
http://www.dotnetfunda.com/articles/show/442/how-to-get-the-values-of-selected-row-from-a-gridview-using-aspnet
http://asp.net-informations.com/gridview/select-row.htm
Khargesh RajputPosted Apr 7, 2015, 5:17 AM
Azaad AbbasPosted Apr 7, 2015, 5:07 AM
Khargesh RajputPosted Apr 7, 2015, 4:38 AM
Azaad AbbasPosted Apr 7, 2015, 4:33 AM
GridViewRow CurrentRow = ctrl.NamingContainer as GridViewRow;
int custId = grdSearch.DataKeys[CurrentRow.RowIndex].Value.ToString();
this will take which cell value?
Gowtham RajamanickamPosted Apr 7, 2015, 4:29 AM
Khargesh RajputPosted Apr 7, 2015, 4:13 AM
May be cell[4] has no value
also try this way
if (e.CommandName == "CompVIEW")
{
int row = Convert.ToInt32(e.CommandArgument);
Control ctrl = e.CommandSource as Control;
GridViewRow CurrentRow = ctrl.NamingContainer as GridViewRow;
int custId = grdSearch.DataKeys[CurrentRow.RowIndex].Value.ToString();
and
in gridview
DataKeyNames="ID" where id will be your complaintid