Vote count:
0
I am creating dynamic dropdownlist in asp.net which is under asp:listview control code is as below
<asp:ListView runat="server" ID="lst" OnItemDataBound="lst_dataBound">
<ItemTemplate>
<asp:DropDownList runat="server" CssClass="test" ID="ddl"></asp:DropDownList>
<asp:HiddenField runat="server" ID="hf" Value='<%# Eval("Id") %>' />
<a class="btn btn-success" id='<%#Eval("ID") %>' onclick="Add('<%#Eval("ID")%>')>Add</a>
</ItemTemplate>
</asp:ListView>
on server side i have given source and bind the list and on item databound event i have binded dropdownlist which is perfetly but as shown above when i click anchor tag i want selected item from drop down for that i have tried this
var item = $('.test option:selected').text();
alert(item);
which is giving me all list items like if i have 10 list so 10 dropdowns so if each have 4 items take text as(1,2,3,4) selected item at each list so randomly it will ("1212134232") which is 10 item in alert but i want single one so i tried another solution i give dynamic cssclass at server side like this
DropDownList myDDL = (DropDownList)e.Item.FindControl("ddl");
HiddenField HF_ID = (HiddenField)e.Item.FindControl("hf");
myDDL.ID = "test" + HF_ID.Value;
so now i have dynamic class name i can access them at jqery - javascript so code which i use them for is
here id is which i will get from function parameter
var test = "test" + id;
var item = $('.test option:selected').text();
alert(item);
here it should give right answer but it is not giving so i try further i inspect element and see if this working and yeah its working dynamic css class they have so i have think further and tried like if dynamic side name given like test20,test21 etc... y not try static value so i tried
var item = $('.test20 option:selected').text();
alert(item);
and yeah its working it is giving me specific dropdown list selected value but this can't be done for statically so i needed help here hope u got my question thx in advance any help will be appreciated and if there is another way then i will also like to know
Aucun commentaire:
Enregistrer un commentaire