DataList : get values

S

SJ

I have a dropdownlist("myList") in my DataList control. When a user selects
one of the
items in the dropdownlist, I need to access the value of the DataBound Label
("myLabel") in the Datalist and display it in a popUp window. I have to do
all of this in Codebehind and not inline scripting. Any idea how I can
accomplish this?

<asp:DataList id="testList" runat="server">
<ItemTemplate>

<asp:DropDownList id="myList" runat="server">
<asp:ListItem value="Item1"></asp:ListItem>
<asp:ListItem value="Item2"></asp:ListItem>
</asp:DropDownList>

<asp:Label id="myLabel"><%# DataBinder.Eval(Container.DataItem,
"DataValue")%>
</asp:Label>

</ItemTemplate>
</asp:DataList>


Thanks.
 
G

Guest

DropDownList ddl =
(DropDownList)datalist.Items[rowIndex].FindControl("myList");
string strValue = ddl.SelectedValue;

HTH

Elton Wang
 
S

SJ

That kind of helped. thanks.
I'm trying to do this in the "myDataList_SelectedIndexChanged" event
handler.
for some reason though, when I select something in the dropdownlist, nothing
happens.


Elton W said:
DropDownList ddl =
(DropDownList)datalist.Items[rowIndex].FindControl("myList");
string strValue = ddl.SelectedValue;

HTH

Elton Wang


SJ said:
I have a dropdownlist("myList") in my DataList control. When a user selects
one of the
items in the dropdownlist, I need to access the value of the DataBound Label
("myLabel") in the Datalist and display it in a popUp window. I have to do
all of this in Codebehind and not inline scripting. Any idea how I can
accomplish this?

<asp:DataList id="testList" runat="server">
<ItemTemplate>

<asp:DropDownList id="myList" runat="server">
<asp:ListItem value="Item1"></asp:ListItem>
<asp:ListItem value="Item2"></asp:ListItem>
</asp:DropDownList>

<asp:Label id="myLabel"><%# DataBinder.Eval(Container.DataItem,
"DataValue")%>
</asp:Label>

</ItemTemplate>
</asp:DataList>


Thanks.
 
G

Guest

Do you have event trigger:

this.myDataList.SelectedIndexChanged += new EventHandler(myDataList
_SelectedIndexChanged);

in method private void InitializeComponent() ?



SJ said:
That kind of helped. thanks.
I'm trying to do this in the "myDataList_SelectedIndexChanged" event
handler.
for some reason though, when I select something in the dropdownlist, nothing
happens.


Elton W said:
DropDownList ddl =
(DropDownList)datalist.Items[rowIndex].FindControl("myList");
string strValue = ddl.SelectedValue;

HTH

Elton Wang


SJ said:
I have a dropdownlist("myList") in my DataList control. When a user selects
one of the
items in the dropdownlist, I need to access the value of the DataBound Label
("myLabel") in the Datalist and display it in a popUp window. I have to do
all of this in Codebehind and not inline scripting. Any idea how I can
accomplish this?

<asp:DataList id="testList" runat="server">
<ItemTemplate>

<asp:DropDownList id="myList" runat="server">
<asp:ListItem value="Item1"></asp:ListItem>
<asp:ListItem value="Item2"></asp:ListItem>
</asp:DropDownList>

<asp:Label id="myLabel"><%# DataBinder.Eval(Container.DataItem,
"DataValue")%>
</asp:Label>

</ItemTemplate>
</asp:DataList>


Thanks.
 
S

SJ

Yes, its there.
Do I have to use RaiseBubbleEvent so that a change in the DropDownlist
inside the
DataList actually works? If so, how do I do this?
Or is there another way to do this?

Thanks.

Elton W said:
Do you have event trigger:

this.myDataList.SelectedIndexChanged += new EventHandler(myDataList
_SelectedIndexChanged);

in method private void InitializeComponent() ?



SJ said:
That kind of helped. thanks.
I'm trying to do this in the "myDataList_SelectedIndexChanged" event
handler.
for some reason though, when I select something in the dropdownlist, nothing
happens.


Elton W said:
DropDownList ddl =
(DropDownList)datalist.Items[rowIndex].FindControl("myList");
string strValue = ddl.SelectedValue;

HTH

Elton Wang


:

I have a dropdownlist("myList") in my DataList control. When a user selects
one of the
items in the dropdownlist, I need to access the value of the
DataBound
Label
("myLabel") in the Datalist and display it in a popUp window. I have
to
do
all of this in Codebehind and not inline scripting. Any idea how I can
accomplish this?

<asp:DataList id="testList" runat="server">
<ItemTemplate>

<asp:DropDownList id="myList" runat="server">
<asp:ListItem value="Item1"></asp:ListItem>
<asp:ListItem value="Item2"></asp:ListItem>
</asp:DropDownList>

<asp:Label id="myLabel"><%# DataBinder.Eval(Container.DataItem,
"DataValue")%>
</asp:Label>

</ItemTemplate>
</asp:DataList>


Thanks.
 
G

Guest

Just a guess, your Datalist’s EnableViewState is set to false. That might
cause this kind problem.

SJ said:
Yes, its there.
Do I have to use RaiseBubbleEvent so that a change in the DropDownlist
inside the
DataList actually works? If so, how do I do this?
Or is there another way to do this?

Thanks.

Elton W said:
Do you have event trigger:

this.myDataList.SelectedIndexChanged += new EventHandler(myDataList
_SelectedIndexChanged);

in method private void InitializeComponent() ?



SJ said:
That kind of helped. thanks.
I'm trying to do this in the "myDataList_SelectedIndexChanged" event
handler.
for some reason though, when I select something in the dropdownlist, nothing
happens.


DropDownList ddl =
(DropDownList)datalist.Items[rowIndex].FindControl("myList");
string strValue = ddl.SelectedValue;

HTH

Elton Wang


:

I have a dropdownlist("myList") in my DataList control. When a user
selects
one of the
items in the dropdownlist, I need to access the value of the DataBound
Label
("myLabel") in the Datalist and display it in a popUp window. I have to
do
all of this in Codebehind and not inline scripting. Any idea how I can
accomplish this?

<asp:DataList id="testList" runat="server">
<ItemTemplate>

<asp:DropDownList id="myList" runat="server">
<asp:ListItem value="Item1"></asp:ListItem>
<asp:ListItem value="Item2"></asp:ListItem>
</asp:DropDownList>

<asp:Label id="myLabel"><%# DataBinder.Eval(Container.DataItem,
"DataValue")%>
</asp:Label>

</ItemTemplate>
</asp:DataList>


Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top