Here I'm showing how to find a control within a gridview to get some data of that control.
<Columns>
<asp:TemplateField HeaderText="Team">
<ItemTemplate>
<asp:Label ID="lblTeam" runat="server" Text='<%# Eval("TeamName")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" Text="EDIT" runat="server" CssClass="coachEdit" CommandArgument='<%# Eval("TeamId")%>' CommandName="Redirect"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Here i need the Team Name from the lblTeam and I'm like to get this when I click the Edit link means lnkEdit so on RowCommand event i have to write this code
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
Label lblDate = (Label)row.Cells[0].FindControl("lblDate");
string teamName= lblDate.Text;
int rowindex = row.RowIndex;
good work dear.... thanks
ReplyDeletethank u very much
ReplyDeletethank u........
ReplyDeleteit great to hear some comments.
ReplyDeletethank you guys..
thanks
ReplyDeleteYou made my evening, thanks Bishnu
ReplyDeletenice tutorial...
ReplyDeletefabulous very helpfull
ReplyDeleteif (e.CommandName == "select")
Delete{
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
ImageButton img = (ImageButton)row.Cells[0].FindControl("ImageButton3");
String url1 = img.ImageUrl.ToString();
Image1.ImageUrl = url1;
}
ImageButton or LinkButton what ever you use for which the RowCommand event get fired please use that control for type cast the e.CommandSource
DeleteLike jatashri use ImageButton so she use like this
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
good work
ReplyDeleteNice post very helpful
ReplyDeletedbakings