c# - How to get the value of dropdownlist on selection changed inside the repeater. -
i have 4 column inside repeater, expected , accpet , ddl & 1 panel not visible on page load
if expect column value , dropdown selection value same want visible panel otherwise not.
please me not getting value of dropdownlist beacuse on selection change whole repeater refilling not single value able get. can me this.
any possible way me.
css
<style> .main { width: 100%; } .inner { width: 90%; } .fst { width: 20%; float: left; } .scnd { width: 20%; float: left; } .thrd { width: 20%; float: left; } .frth { width: 20%; float: left; } .reset-this { clear:both; } </style>
html
<div class="main"> <div class="inner"> <div class="fst"> except </div> <div class="scnd"> accpet </div> <div class="thrd"> ddl </div> <div class="frth"> panel </div> <div class="reset-this"> </div> </div> <div class="reset-this"> </div> <br /> <asp:repeater id="repeater1" runat="server" onitemdatabound="repeater1_itemdatabound"> <itemtemplate> <div class="inner"> <div class="fst"> <asp:label id="label1" runat="server" text='<%# eval("expected") %>'></asp:label> </div> <div class="scnd"> <asp:label id="label2" runat="server" text='<%# eval("accpet") %>'></asp:label> </div> <div class="thrd"> <asp:dropdownlist id="dropdownlist3" autopostback="true" runat="server" onselectedindexchanged="dropdownlist3_selectedindexchanged"> <asp:listitem text="select" value="-1"></asp:listitem> <asp:listitem text="50"></asp:listitem> <asp:listitem text="51"></asp:listitem> <asp:listitem text="52"></asp:listitem> <asp:listitem text="53"></asp:listitem> <asp:listitem text="100"></asp:listitem> </asp:dropdownlist> </div> <div class="frth"> <asp:panel id="panel1" runat="server"> <asp:dropdownlist id="dropdownlist2" runat="server"> <asp:listitem text="succesful"></asp:listitem> </asp:dropdownlist> </asp:panel> </div> <div class="reset-this"> </div> <br /> </div> </itemtemplate> </asp:repeater> </div>
codebehind
protected void page_load(object sender, eventargs e) { getdataset(); } public void getdataset() { dataset ds = new dataset(); datatable dt = new datatable("warehousetable"); dt.columns.add(new datacolumn("expected", typeof(string))); dt.columns.add(new datacolumn("accpet", typeof(string))); datarow dr = dt.newrow(); dr["expected"] = "100"; dr["accpet"] = "50"; dt.rows.add(dr); datarow dr1 = dt.newrow(); dr1["expected"] = "50"; dr1["accpet"] = "25"; dt.rows.add(dr1); ds.tables.add(dt); repeater1.datasource = ds; repeater1.databind(); } protected void repeater1_itemdatabound(object sender, repeateritemeventargs e) { ((panel)(e.item.findcontrol("panel1"))).visible = false; } protected void dropdownlist3_selectedindexchanged(object sender, eventargs e) { (int = 0; < repeater1.items.count; i++) { panel pnl_active = repeater1.items[i].findcontrol("panel1") panel; label expected = repeater1.items[i].findcontrol("label1") label; dropdownlist ddlvalue = repeater1.items[i].findcontrol("dropdownlist3") dropdownlist; if (ddlvalue.selecteditem.tostring() == expected.tostring()) { pnl_active.visible = true; } } }
you need couple of things:
first, add in page_load
method avoid resetting repeater's values:
protected void page_load(object sender, eventargs e) { if (!ispostback) { getdataset(); } }
next, modify dropdownlist3_selectedindexchanged
method this:
protected void dropdownlist3_selectedindexchanged(object sender, eventargs e) { (int = 0; < repeater1.items.count; i++) { panel pnl_active = repeater1.items[i].findcontrol("panel1") panel; label expected = repeater1.items[i].findcontrol("label1") label; dropdownlist ddlvalue = repeater1.items[i].findcontrol("dropdownlist3") dropdownlist; //you need compare selecteditem.text label expected.text if (ddlvalue.selecteditem.text == expected.text) { pnl_active.visible = true; } } }
notice comparing ddlvalue.selecteditem label expected, not correct because need compare ddlvalue.selecteditem.text label expected.text.
hope helps.
Comments
Post a Comment