asp.net listview and findcontrol -
i have listview , need bind dropdown list in list view listitemcollection built using function bindpages(). when clicked on addnew link not able bind dropdown.
<asp:listview datakeynames="menuid" onitemcommand="lvparentmenus_itemcommand" onsorting="lvparentmenus_sorting" ondatabound="lvparentmenus_databound" datasourceid="sqldatasource1" id="lvparentmenus" runat="server"> <layouttemplate> <table border="0" id="listview" width="100%" class="grid" cellpadding="0" cellspacing="0"> <thead> <tr class="listingheader "> <td width="10%" style="text-align: center; !important"> <input type="checkbox" name="checkbox" id="headercheck" /> </td> <td id="thsno" runat="server"> <asp:linkbutton id="linkbutton1" runat="server" commandname="sort" commandargument="sno" text="sno" /> </td> <td id="thmenutext" runat="server"> <asp:linkbutton runat="server" id="linkbutton2" text="menu text" commandname="sort" commandargument="menutext" /> </td> <td id="thmenuurl" runat="server"> <asp:linkbutton runat="server" id="linkbutton3" text="menu url" commandname="sort" commandargument="menuurl" /> </td> <td id="thlevel" runat="server"> <asp:linkbutton runat="server" id="linkbutton4" text="level of display" commandname="sort" commandargument="level" /> </td> <td> action </td> </tr> </thead> <tbody> <tr runat="server" id="itemplaceholder"> </tr> </tbody> <tfoot> <tr> <td colspan="3" align="center"> <asp:label id="lblmessage" text="dfdfdfd" runat="server"></asp:label> </td> <td align="right"> <asp:linkbutton text="add new" id="lnknew" commandname="filldropdown" runat="server" font-bold="true" onclick="addnew"></asp:linkbutton> </td> </tr> </tfoot> </table> <itemtemplate> <tr class='<%# container.dataitemindex % 2 == 0 ? "lrow1" : "lrow1 altrow" %>'> <td class="col1" align="center"> <asp:checkbox runat="server" id="chkitem"></asp:checkbox> </td> <td class="lrow1"> <%# eval("sno")%> <asp:hiddenfield id="hdnstoreid" runat="server" value='<%# eval("menuid") %>' /> </td> <td> <%# eval("menutext")%> </td> <td> <asp:dropdownlist id="ddlpageslist" runat="server" datasource='<%#bindpages()%>'> </asp:dropdownlist> </td> <td> <asp:dropdownlist id="ddllevel" runat="server" datasource='<%#bindlevel(6)%>' selectedvalue='<%# eval("level")%>'> </asp:dropdownlist> </td> <td nowrap="nowrap"> <asp:linkbutton id="lnkedit" runat="server" commandname="edit">edit</asp:linkbutton> | <asp:linkbutton id="lnkdelete" runat="server" commandname="delete" onclientclick="javascript:return confirm('are sure delete current item');">delete</asp:linkbutton> </td> </tr> </itemtemplate> <insertitemtemplate> <tr class="lrow1"> <td class="col1" align="center"> </td> <td class="lrow1"> </td> <td class="lrow1"> <asp:textbox id="txtmenutext" runat="server" width="80px" text='<%# eval("menutext")%>' cssclass="inputbox" validationgroup="insertfields" /> <asp:requiredfieldvalidator id="reqvalidcity" controltovalidate="txtmenutext" runat="server" errormessage="city name required." display="dynamic" validationgroup="insertfields">*</asp:requiredfieldvalidator> <asp:regularexpressionvalidator id="regvalidcity" runat="server" errormessage="please enter alphabets only." display="dynamic" validationgroup="g1" controltovalidate="txtmenutext" validationexpression="^[a-za-z0-9\s]{2,1000}"></asp:regularexpressionvalidator> </td> <td> <asp:dropdownlist id="ddlpageslist" runat="server" datasource='<%#bindpages()%>'> </asp:dropdownlist> </td> <td> <asp:dropdownlist id="ddllevel" runat="server" datasourceid="sdslevel" datavaluefield="level" datatextfield="level"> </asp:dropdownlist> </td> <td nowrap="nowrap"> <asp:linkbutton id="lnkinsert" runat="server" onclick="lnkinsert_click" validationgroup="insertfields"> insert</asp:linkbutton> </td> </tr> </insertitemtemplate> </asp:listview> <asp:sqldatasource id="sqldatasource1" runat="server" selectcommand="usp_getparentmenus" selectcommandtype="storedprocedure"> <selectparameters> <asp:controlparameter controlid="ddlroles" name="introleid" propertyname="text" defaultvalue="1" convertemptystringtonull="true" direction="input" /> </selectparameters> </asp:sqldatasource>
and here method bindpages()
protected listitemcollection bindpages() { string sdir = request.physicalapplicationpath; if (firstcount == 0) dirsearch(sdir); return collection; }
when tried find ddlpagelist in addnew() method throwing error "object referenc not set "
addnew() method: ` protected void addnew(object sender, eventargs e) {
lvparentmenus.insertitemposition = insertitemposition.firstitem; lvparentmenus.findcontrol("lnknew").visible = false; lvparentmenus.editindex = -1; sdslevel.connectionstring = dbconnectionstring.connectionstring; parameter = new parameter("introleid", dbtype.int32); a.defaultvalue = ddlroles.selectedvalue.tostring(); sdslevel.selectparameters.add(a); sdslevel.selectcommand = "usp_getparentmenus"; dropdownlist ddlpages = (dropdownlist)lvparentmenus.findcontrol("ddlpageslist"); string sdir = request.physicalapplicationpath; dirsearch(sdir); ddlpages.datasource = collection;
ddlpages.databind(); }
need urgently. thanks.
please try
dropdownlist ddlpages = (dropdownlist)lvparentmenus.items[0].findcontrol("ddlpageslist");
Comments
Post a Comment