Reputation: 220
I am developing a web application for Medical shop, I am getting some problem their that i am explaining here. I have one Link button in a gridview and gridview is inside datalist in asp.net How can I find a gridview linkbutton control inside a datalist? Code Here
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate></HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="btnButton" OnClick="btnButton_Click">LinkButton</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:DataList>
This is Design file code, please review this and help me, If you have any solution for this.
Upvotes: 0
Views: 1045
Reputation: 1250
First you have to find gird in datalist as below
int index = e.Item.ItemIndex;
GridView gv = (GridView)Datalist1.Items[index].FindControl("grid");
Then you have to find that control in gridview
int rowIndex = ((GridViewRow((LinkButton)e.CommandSource).NamingContainer).RowIndex;
string title = ((TextBox)gv.Rows[rowIndex].FindControl("txtTitle")).Text;
Hope it will help you to get your solution..
Upvotes: 1