asp.net - I am unable to use FileUpload which is in Gridview in the UpdatePanel, have also used trigger, how can i solve this? -
i want use updatepanel
gridview
, fileupload
in gridview
doesn't work if added trigger... because cant find fileupload
button
, whats solution?
<asp:templatefield headertext="upload kundli"> <itemtemplate> <asp:fileupload id="fileupload1" runat="server" /><br /> <asp:button id="btnupload" runat="server" text="upload" onclick="btnupload_click" /> </itemtemplate> <itemstyle horizontalalign="center" /> <headerstyle horizontalalign="center" /> </asp:templatefield> </columns> </asp:gridview> </contenttemplate> <triggers> <asp:postbacktrigger controlid="btnupload" /> </triggers> </asp:updatepanel>
here way via code behind, dummy mockup give idea:
aspx code:
<form id="form1" runat="server"> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:updatepanel runat="server"> <contenttemplate> <asp:label runat="server" id="label1" text=""></asp:label> <asp:gridview runat="server" id="gridview1" onrowdatabound="gridview1_rowdatabound"> <columns> <asp:templatefield headertext="upload kundli"> <itemtemplate> <asp:fileupload id="fileupload1" runat="server" /><br /> <asp:button id="btnupload" runat="server" text="upload" onclick="btnupload_click" /> </itemtemplate> <itemstyle horizontalalign="center" /> <headerstyle horizontalalign="center" /> </asp:templatefield> </columns> </asp:gridview> </contenttemplate> </asp:updatepanel> </form>
code behind (aspx.cs):
protected void page_load(object sender, eventargs e) { if (!ispostback) { list<int> griditems = new list<int>(); griditems.add(1); griditems.add(2); gridview1.datasource = griditems; gridview1.databind(); } } protected void gridview1_rowdatabound(object sender, gridviewroweventargs e) { //may not need if. check depending on , how binding. if (e.row.rowtype == datacontrolrowtype.datarow) { button uploadbuton = (button) e.row.cells[0].findcontrol("btnupload"); if(uploadbuton != null) { if (this.scriptmanager1 != null) { this.scriptmanager1. registerasyncpostbackcontrol(uploadbuton); } } } } protected void btnupload_click(object sender, eventargs e) { label1.text = label1.text + "a"; }
Comments
Post a Comment