How to call more than a value in Grid View in ASP.NET 4.0 C#.net
I'm new to ASP.NET 4.0. In my project, the data'a are displayed in the Grid View. The user selects a row to edit based on two values which are stored in the Database. My code for calling single value is given here. How can I get datas based on two values from the database. PLease help me with this.
grdViewVacationInfo_RowCommand()
{
if (e.CommandName == "ViewInfoBtn")
{
int index = int.Parse(e.CommandArgument.ToString());
string key = grdViewVacationInfo.DataKey开发者_如何学运维s[index].Value.ToString();
Session["ke"] = key.ToString();
}
}
This is how ill call a single value. but how can i get the more than two values and store it in a Session or any variable.
Thanks In Advance
you can try this to fatch grid's column value .
grdViewVacationInfo.Rows[grdViewVacationInfo.SelectedIndex]..Cells[yourcellindex].Text;
As you're already using DataKeys
you're most of the way there already. DataKeys can hold more than one value - just separate the column names you want with commas:
<asp:gridview runat="server" id="grdViewVacationInfo"
DataKeyNames="Column1, Column2"
...
</asp:gridview>
Then in your RowCommand event, you access the DataKey values by index:
grdViewVacationInfo_RowCommand()
{
if (e.CommandName == "ViewInfoBtn")
{
int index = int.Parse(e.CommandArgument.ToString());
string key1 = grdViewVacationInfo.DataKeys[index].Value[0].ToString();
string key2 = grdViewVacationInfo.DataKeys[index].Value[1].ToString();
Session["ke"] = key1;
Session["ke2"] = key2;
}
}
精彩评论