hello every one
I want to use many values from gridview on row command of gridview then what would i use.
i have been using many label in gridview to bind the values of id, name, subject etc.
for example i want to store
name and subject in session from gridview on row command then what would i use. please tell me
Loading

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Oct 4, 2013, 10:09 AM EDT
Use like this on Row Command Button,
CommandArgument="" /> And then, In code behind, protected void grdexam_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "dtls") { int index = int.Parse(e.CommandArgument.ToString()); Label paperid = (Label)grdexam.Rows[index].FindControl("Label1"); Label subject = (Label)grdexam.Rows[index].FindControl("testname"); SqlCommand cmd = new SqlCommand("select * from ExamMaster where groupid='" + Session["grpid"] + "' and papercode='" + paperid.Text + "'", con); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { GridView1.DataSource = dt; GridView1.DataBind(); pnlsubbjectiv.Visible = true; } else { Response.Write("wromg"); } } }Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Sep 30, 2013, 1:46 AM EDT
Try something like this.
protected void gridMembersList_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add") // Or something
{
int index = Convert.ToInt32(e.CommandArgument.ToString());
Literal ltrlslno = (Literal)gridMembersList.Rows[index].FindControl("ltrlSlno");
Literal ltrlName = (Literal)gridMembersList.Rows[index].FindControl("ltrlName"); Session["ltrlName "] = ltrlName.Text;
}
}
Gopal Ji Singh39 reputationPosted Sep 30, 2013, 2:13 AM EDT
Then i m facing this error(Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index) please help me
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Sep 30, 2013, 10:28 PM EDT
Gopal Ji Singh39 reputationPosted Oct 4, 2013, 12:30 AM EDT
my GridView script given bellow...
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None" AutoGenerateColumns="False" onrowcommand="grdexam_RowCommand"
>
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 4, 2013, 12:35 AM EDT
Gopal Ji Singh39 reputationPosted Oct 16, 2013, 10:54 PM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Oct 17, 2013, 12:44 AM EDT