Getting BoundField Value in gridview row_command
I need to get the bound开发者_如何学JAVA field value of the selected column in gridview_rowcommand.
Any ideas?
it will be like...
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
row.Cells[0].Text
It should be something like this.
if (e.CommandName=="CommandName")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
string boundFieldText= row.Cells[0].Text;
}
To take the value of the field from grid view, first set the datakeyname then in default.aspx.cs page write below code:
//this is for linkbutton onclick u can use button also
## Coding ##
protected void lnkDownload_Click(object sender, EventArgs e)
{
LinkButton lnkbtn = sender as LinkButton;
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
string username= gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
}
精彩评论