Find Control and cell data in Grid Row Command event

Manojjupally
Posted by Manojjupally under ASP.NET category on | Points: 40 | Views : 1272
Grid View


 <asp:GridView ID="grdUsers" runat="server" AutoGenerateColumns="false" OnRowCommand="grdUsers_RowCommand" OnRowDataBound="grdUsers_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept">
<ItemTemplate>
<%#Eval("Dept") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sal">
<ItemTemplate>
<%#Eval("Sal") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image ID="imgUser" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<%#Eval("Status") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Change">
<ItemTemplate>
<asp:LinkButton ID="lnkChange" runat="server" CommandName="Change" username = <%#Eval("Name") %>>Change</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


Row Command Event


protected void grdUsers_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Change")
{
DataTable dtusers = (DataTable)Session["users"];
LinkButton lnkbtn = (LinkButton)e.CommandSource;
GridViewRow gvrow = (GridViewRow)((lnkbtn).NamingContainer);
string name = lnkbtn.Attributes["username"];
Image img = (Image)gvrow.FindControl("imgUser");
}
}

Comments or Responses

Login to post response