Showing posts with label selectedvalue. Show all posts
Showing posts with label selectedvalue. Show all posts

Saturday, March 24, 2012

DropDownList2.DataValueField = DropDownList1.SelectedValue

Hello, I have a webpage with 2 DDL controls. DDL1.SelectedValue = DDL2.DataValueField. Everthing works fine if I have DDL1 AutoPostBack checked. I would like to eliminate the postbacks. Below is my code. I do not know why it doesn't work.

Thanks! Steve

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged

Dim strDataTextFieldAsString

DropDownList2.DataValueField = DropDownList1.SelectedValue

strDataTextField = DropDownList1.SelectedValue

strDataTextField = strDataTextField &"text"

DropDownList2.DataTextField = strDataTextField

EndSub

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"SelectCommand="SELECT * FROM [Futures]"></asp:SqlDataSource>

<asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"SelectCommand="SELECT * FROM [Months]"></asp:SqlDataSource>

<asp:DropDownListID="DropDownList1"runat="server"Style="z-index: 100; left: 342px; position: absolute; top: 86px"DataSourceID="SqlDataSource1"DataTextField="Text"DataValueField="Value"></asp:DropDownList>

<asp:DropDownListID="DropDownList2"runat="server"Style="z-index: 102; left: 616px; position: absolute; top: 86px"DataSourceID="SqlDataSource2"></asp:DropDownList>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

</div>

</form>

</body>

SelectedIndexChanged is a server-side event which occurs only after a postback. If you inserted a breakpoint, you'd find that the program never gets there.

DisturbedBuddha:

SelectedIndexChanged is a server-side event which occurs only after a postback. If you inserted a breakpoint, you'd find that the program never gets there.

So what do I do to fix that?

Thanks Steve


Set AutoPostBack="true" for the dropdownlist and just place the dropdownlist in its own updatepanel to hide the visible refresh.


Hello, I already have my dropdownlist1 in an updatepanel with autopostback="true" and the whole page refreshes. If autopostback="false" nothing happens.

Please look at my code on top again.

Thanks for the help

Steve

Dropdownlist in Update Panel

Hello everyone,

can you please tell me how to read or set SelectedValue property of a dropdownlist which is located inside a update panel? I can reference it with no problems but all I get is an empty string. Assigning a value doesn't do anything.

Thanks,
Radoslav

The same way you do when you have no UpdatePanel.

Post your code and let us see what you are doing wrong in !


It is same ,when u use it normally.

No extra code, just you have to declare the DropDownList inside the UpdatePanel


Can you provide some code details ...So it will be helpful.

<asp:ScriptManager ID="sm1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel 1" UpdateMode="Conditional" runat="server">
<ContentTemplate>

<asp:DropDownList ID="itemNumber" runat="server" OnSelectedIndexChanged="itemNumber_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>

</ContentTemplate>
</asp:UpdatePanel>


Hope it will help youSmile