Get DataKeyName value on rowcommand and rowdatabound event in asp.net
Simplest way to get Datakeyname Value on rowcommand and rowdatabound event in asp.net
<asp:GridView ID="Grd" runat="server DataKeyNames="rowid ,
Status , Sender , sscalltime"
onrowcommand="GridINfo_RowCommand"
onrowdatabound="GridINfo_RowDataBound">
<Columns>
<asp:TemplateField ItemStyle-Width="120px" >
<ItemTemplate> <asp:Button ID="Button2"
CssClass="button-blue"
runat="server" CommandName="Note" Text="Add Note"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void
GridINfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Status = Convert.ToString(GridINfo.DataKeys[e.Row.RowIndex].Values["Status"]);
}
}
protected void
GridINfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Note")
{
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int rowIndex = row.RowIndex; //Convert.ToInt32(e.CommandArgument);
string ID = Convert.ToString(GridINfo.DataKeys[rowIndex].Values["rowid"]);
}
}
Comments
Post a Comment