last day (14 days later) » 

3:29 PM
0
A: Locating a control inside ListView template field

LegendsThis might work for you protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e) { var lw = sender as ListView; var ddl = lw.Items[e.NewSelectedIndex].FindControl("DropDownList1") as DropDownList; var val = ddl.SelectedV...

 
This event won't fire when user selects something from the dropdown list which is in the template field of the list view, so this doesn't helps at all... I believe I need on selected index changing event from drop down list, but I can't seem to find it??? Thers only "on selected index changed"...
 
Thats the event ur looking for! then you have to add a DropDownList1_SelectedIndexChanged to the dropdownlist and then access the value there.
 
Can you write me the code how you think it should look like, because I'm not quite sure what to do with the code you gave me above... Thanks!
 
can u post the code of your listview to see what you are doing...
 
Okay sure, give me few minutes to get the code... Btw, this event should fire every time user changes the dropdown selection?
 
3:29 PM
why few minutes, just post the code as u have it.
 
Posted the html code of listview...
 
why OnTextChanged="DropDownList1_TextChanged"
you need <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
 
okay i did it
but the event doesnt fires at all ?
i change the ddl selection , but the evnt isnt fired up...
 
did u implement the event in your code behind?
event handler
this part:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
var ddl = sender as DropDownList;
var val = ddl.SelectedValue;
}
and remove this part
OnTextChanged="DropDownList1_TextChanged"
there is no OnTextChanged event implemented in ddl
 
aha okay i see
and i also needed to put "autopostback = true"
since the event wasn't firing at all
it works
can i ask u one more question?
 
3:42 PM
sure
 
i also need to locate one more control inside that template field
its a label
that will write out product price when user selects it from the ddl
but im not sure how should i do it
 
try it like that
ddl.Parent.FindControl("labelIdXYZ") as Label
 
lol okay thats easier than i imagined it :D
 
or
ddl.Parent.Parent.FindControl("labelIdXYZ") as Label
depends now, u have to test it
 
okay ill try bothj
 
3:45 PM
just mark it as an answer ;-)
 
allrighty ;)
yap it works!:D
first one actually...
 
if doesnt work just ask me
 
hey quick question
 
but i have to go now and will come back later
good luck !
 
okay :)
ty!
 

last day (14 days later) »