c# - How can I access to a ServerControl exists inside an ItemTemplate? -
i have following listview
:
<asp:listview id="procedureticketlist" runat="server" ... <itemtemplate> <asp:gridview id="mygridview" runa...
how can access mygridview
programmatically ?
try following code snippet.
protected void procedureticketlist_databound(object sender, eventargs e) { gridview gv= ((gridview)e.item.findcontrol("mygridview")); . . . }
edit:
check following code snippet.
<%@ page language="c#" autoeventwireup="true" codefile="default2.aspx.cs" inherits="default2" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:listview runat="server" id="_simpletablelistview" onitemdatabound="_simpletablelistview_itemdatabound"> <layouttemplate> <table> <thead> <tr> <th> id </th> <th> title </th> </tr> </thead> <tbody> <asp:placeholder runat="server" id="itemplaceholder" /> </tbody> </table> </layouttemplate> <itemtemplate> <tr> <td> <%# eval("id") %> </td> <td> <%# eval("title") %> </td> <td> <asp:gridview id="mygridview" runat="server"> </asp:gridview> </td> </tr> </itemtemplate> </asp:listview> </div> </form> </body> </html> using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class default2 : system.web.ui.page { protected void page_load(object sender, eventargs e) { _simpletablelistview.datasource = new movie().getall; _simpletablelistview.databind(); } protected void _simpletablelistview_itemdatabound(object sender, listviewitemeventargs e) { gridview gv= ((gridview)e.item.findcontrol("mygridview")); } } public class movie { public int id { get; set; } public string title { get; set; } public list<movie> getall { { return new list<movie>() { new movie{id=1,title="a"}, new movie{id=2,title="b"}, }; } } }
Comments
Post a Comment