Cascading Dropdownlist - setting selected value

Hi, I would appreciate some help please! Thanks in advance.

I am trying to set the selected value of two cascadingdropdowns. I am using javascript (if someone has a better suggestion I am all ears!). The problem I am having is that the dropdowns don't seem to be loaded by the time I try to set the values. I put in a couple alerts, so that pauses the javascript long enough for the dropdowns to load, then the code works. If I take out the alerts the code no longer works. How should I go about setting the selected value?

This is the javascript:

<script type="text/javascript">
  function pageLoad() {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (!prm.get_isInAsyncPostBack()) {
      if ('<%=sAssetCategory%>' != '') {
        alert('<%=sAssetCategory%>');
        document.getElementById('FormView1_ddlAssetCategory').value = '<%=sAssetCategory%>';
      }
      if ('<%=sAssetSubCategory%>' != '') {
        if ($find('CascadingDropDown2') != null) {
        $find('CascadingDropDown2')._onParentChange(false);
        alert('<%=sAssetSubCategory%>');
        document.getElementById('FormView1_ddlAssetSubCategory').value = '<%=sAssetSubCategory%>';
        }
      }
    }
  }
</script>

0
Rowena
3/9/2009 9:44:18 PM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

12 Replies
2533 Views

Similar Articles

[PageSpeed] 41

You may want to look into the begin & end request of the script Manager. I have a demo that uses the script manager to do something before and after the asyn post backs taht may help

I realize the example has nothing to do with the Drop Down boxes but the method of attaching events to the Sys.WebForms.PageRequestManager.getInstance();  will definitly help

http://www.obilit.com/Examples/CustomJSMDE/

 

<script type="text/javascript">  
                    Sys.Application.add_load(ApplicationLoadHandler);   
                    function ApplicationLoadHandler(sender, args) {   
                        var prm1 = Sys.WebForms.PageRequestManager.getInstance();   
                        if (!prm1.get_isInAsyncPostBack()) {   
                            //the key here is that i have two events that will fire at a specic moment
                            prm1.add_initializeRequest(initRequest);   
                            prm1.add_endRequest(endRequest);   
                        }   
                    }   
                    function initRequest(sender, args) {   
                        // Load the js objects onto the page   
                        create_Wait("Please wait while we load your data");   
                        createPopupBackground();   
  
                    }   
                    function endRequest(sender, args) {   
                        //remove the Js objects from the page   
                        destroyPopupBackground();   
                        destroyWait();   
                    }   
                         
 
Please mark post as answer
Obilit.com - Progressive Web Methodologies

My Blog
0
nvanhaaster
3/9/2009 11:29:44 PM

Just try to set the value in beginRequest Event  & endRequest Event of Sys.WebForms.PageRequestManager

http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerBeginRequestEvent.aspx

 


Chetan Sarode
Software Engineer,
Approva Systems Pvt Ltd,
Pune, India.
0
chetan
3/10/2009 3:30:58 AM

Hi

As you said you are working with CascadingDropDown controls , you can use the following methods of CascadingDropDown control to access the selected value :-

var ddl = $find('<behaviour id of CascadingDropDown control>');
var value = ddl.get_SelectedValue(); --> for getting the selected value
ddl.set_SelectedValue(value , text); --> to set the value

I will also suggest you to have a look at the internal source code of the dropdown control
wherein you can see couple of getter and setter methods , which you can use in your client side code to invoke methods on the control , attach event handlers etc .

Also In you code I can see you are assigning value to a property called _onParentChange to false .
For this please remember that any property which starts with an underscore(_) is a private property and should not be used directly in your code .

 


Regards
Pawan Mishra
“The greatest compliment that was ever paid to me was when one asked me what I thought, and attended to my answer.” - Henry David Thoreau
0
Pawan_Mishra
3/10/2009 4:22:45 AM

Thanks for the responses.

I don't know how to get the BeginRequest and EndRequest events to fire. They fire if I click the Update button, but I want to set the selected value when the page loads. Any suggestions? I will post all my code...

aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" ValidateRequest="false" EnableEventValidation="False"%>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>RDOS - Enter New Asset</title>

<style type="text/css">

.style1

{

width: 124px;

}

.style2

{

width: 128px;

}

</style> </head>

<body>

<form id="form1" runat="server">

<div>

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

<Services>

<asp:ServiceReference Path="AssetManagement.asmx" />

</Services>

</asp:ScriptManager>

<script type="text/javascript">

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

 

function BeginRequestHandler(sender, args) { alert('BeginRequestHandler');

}

 

function EndRequestHandler(sender, args) {

alert('EndRequestHandler');

if ('<%=sAssetCategory%>' != '') {

alert('<%=sAssetCategory%>');

document.getElementById('FormView1_ddlAssetCategory').value = '<%=sAssetCategory%>';

}

if ('<%=sAssetSubCategory%>' != '') {

if ($find('CascadingDropDown2') != null) {

$find('CascadingDropDown2')._onParentChange(false);

alert('<%=sAssetSubCategory%>');

document.getElementById('FormView1_ddlAssetSubCategory').value = '<%=sAssetSubCategory%>';

}

}

}

</script>

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">

<ContentTemplate>

<asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1" Width="800px">

<EditItemTemplate>

<asp:Label ID="lblFund" runat="server" Text="Fund" />

<br />

<asp:DropDownList ID="ddlFund" runat="server" DataSourceID="SqlDataSource2" DataTextField="Fund" DataValueField="Fund"/>

<br />

<asp:Label ID="lblSegment" runat="server" Text="Segment" />

<br />

<asp:DropDownList ID="ddlSegment" runat="server" DataSourceID="SqlDataSource3" DataTextField="Segment" DataValueField="Segment" />

<br />

<asp:Label ID="lblAssetCategory" runat="server" Text="Asset Category" />

<br />

<asp:DropDownList ID="ddlAssetCategory" runat="server" DataTextField="AssetCategory" DataValueField="AssetCategory" />

<br />

<asp:Label ID="lblAssetSubCategory" runat="server" Text="Asset Sub Category" />

<br />

<asp:DropDownList ID="ddlAssetSubCategory" runat="server" DataTextField="AssetSubCategory" DataValueField="AssetSubCategory" />

<br />

<asp:Button ID="UpdateButton" CommandName="Update" runat="server" Text="Update" />

<br />

<asp:Button ID="InsertButton" CommandName="Insert" runat="server" Text="Insert" />

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlAssetCategory" Category="AssetCategory" PromptText="Please select a category" LoadingText="[Loading categories...]" ServiceMethod="GetAssetCategories" ServicePath="AssetManagement.asmx" />

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddlAssetSubCategory" Category="AssetSubCategory" PromptText="Please select a subcategory" LoadingText="[Loading subcategories...]" ServiceMethod="GetAssetSubCategories" ServicePath="AssetManagement.asmx" ParentControlID="ddlAssetCategory" BehaviorID="CascadingDropDown2" />

</EditItemTemplate>

</asp:FormView>

</asp:Panel>

</ContentTemplate>

</asp:UpdatePanel>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>"

InsertCommand="INSERT INTO AssetManagementMain ([Fund], [Segment], [AssetCategory], [AssetSubCategory]) VALUES (@ddlFund, @ddlSegment, @ddlAssetCategory, @ddlAssetSubCategory)"

UpdateCommand="UPDATE AssetManagementMain SET [Fund] = @ddlFund, [Segment] = @ddlSegment, [AssetCategory] = @ddlAssetCategory, [AssetSubCategory] = @ddlAssetSubCategory WHERE [ID] = @ID"

SelectCommand="SELECT [ID], [Fund], [Segment], [AssetCategory], [AssetSubCategory] FROM AssetManagementMain WHERE [ID] = @ID">

<InsertParameters>

<asp:ControlParameter ControlID="FormView1" Name="ddlFund" PropertyName="SelectedValue" Type="String" />

<asp:ControlParameter ControlID="FormView1" Name="ddlSegment" PropertyName="SelectedValue" Type="String"/>

<asp:ControlParameter ControlID="FormView1" Name="ddlAssetCategory" PropertyName="SelectedValue" Type="String"/>

<asp:ControlParameter ControlID="FormView1" Name="ddlAssetSubCategory" PropertyName="SelectedValue" Type="String"/>

</InsertParameters>

<UpdateParameters>

<asp:ControlParameter ControlID="FormView1" Name="ddlFund" PropertyName="SelectedValue" Type="String" />

<asp:ControlParameter ControlID="FormView1" Name="ddlSegment" PropertyName="SelectedValue" Type="String"/>

<asp:ControlParameter ControlID="FormView1" Name="ddlAssetCategory" PropertyName="SelectedValue" Type="String"/>

<asp:ControlParameter ControlID="FormView1" Name="ddlAssetSubCategory" PropertyName="SelectedValue" Type="String"/>

<asp:Parameter Name="ID" />

</UpdateParameters>

<SelectParameters>

<asp:Parameter Name="ID" />

</SelectParameters>

</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>" SelectCommand="SELECT Fund, Description FROM AssetManagementFund" ></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:RDOS_AppConnectionString %>" SelectCommand="SELECT Segment FROM AssetManagementSegment" ></asp:SqlDataSource>

</div>

</form> </body>

</html>

aspx.vb:

Option Explicit On Option Strict On

Imports System.Data

Imports System.Data.SqlClient

Partial Public Class _Default Inherits System.Web.UI.Page

Friend sAssetCategory, sAssetSubCategory As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

'Retrieve mode and user entered ID.

Dim temp As String = Request.QueryString("Mode").ToString

Dim iID As Integer

If IsNumeric(Request.Form("ID")) = True Then

iID = CInt(Request.Form("ID"))

End If

Select Case temp

Case "Insert"

FormView1.ChangeMode(FormViewMode.Insert)

FormView1.DefaultMode = FormViewMode.Insert

Case "Edit"

'Set UpdateParameter and SelectParameter

Dim paramID As Parameter

paramID = New Parameter

paramID = SqlDataSource1.UpdateParameters.Item("ID")

paramID.DefaultValue = iID.ToString

paramID =
New ParameterparamID = SqlDataSource1.SelectParameters.Item("ID")

paramID.DefaultValue = iID.ToString

FormView1.ChangeMode(FormViewMode.Edit)

FormView1.DefaultMode = FormViewMode.Edit

Case Else

'Set SelectParameter

Dim paramID As Parameter

paramID = New Parameter

paramID = SqlDataSource1.UpdateParameters.Item("ID")

paramID.DefaultValue = iID.ToString

paramID =
New ParameterparamID = SqlDataSource1.SelectParameters.Item("ID")

paramID.DefaultValue = iID.ToString

FormView1.ChangeMode(FormViewMode.ReadOnly)

FormView1.DefaultMode = FormViewMode.ReadOnly

End Select

SqlDataSource1.DataBind()

End If

End Sub

Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete

Dim sMode As String

sMode = FormView1.DefaultMode.ToString

Select Case sMode

Case "Insert"

CType(FormView1.FindControl("InsertButton"), Button).Visible = True

CType(FormView1.FindControl("UpdateButton"), Button).Visible = False

Case "Edit"

CType(FormView1.FindControl("InsertButton"), Button).Visible = False

CType(FormView1.FindControl("UpdateButton"), Button).Visible = True

Case Else

CType(FormView1.FindControl("InsertButton"), Button).Visible = False

CType(FormView1.FindControl("UpdateButton"), Button).Visible = False

End Select

SqlDataSource1.DataBind()

If FormView1.CurrentMode = FormViewMode.Edit Then

Dim rowView As DataRowView = CType(FormView1.DataItem, DataRowView)

If Not IsNothing(rowView) Then

Dim sColumnValue As String

sColumnValue = rowView.Item("Fund").ToString()

If Not IsNothing(CType(FormView1.FindControl("ddlFund"), DropDownList).Items.FindByValue(sColumnValue)) Then

CType(FormView1.FindControl("ddlFund"), DropDownList).SelectedValue = sColumnValue

End If

sColumnValue = rowView.Item("Segment").ToString()

If Not IsNothing(CType(FormView1.FindControl("ddlSegment"), DropDownList).Items.FindByValue(sColumnValue)) Then

CType(FormView1.FindControl("ddlSegment"), DropDownList).SelectedValue = sColumnValue

End If

sAssetCategory = rowView.Item("AssetCategory").ToString()

sAssetSubCategory = rowView.Item("AssetSubCategory").ToString()

End If

End If

End Sub

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInsertinge.Values("ddlFund") = CType(FormView1.FindControl("ddlFund"), DropDownList).SelectedValue

e.Values("ddlSegment") = CType(FormView1.FindControl("ddlSegment"), DropDownList).SelectedValue

e.Values("ddlAssetCategory") = CType(FormView1.FindControl("ddlAssetCategory"), DropDownList).SelectedValue e.Values("ddlAssetSubCategory") = CType(FormView1.FindControl("ddlAssetSubCategory"), DropDownList).SelectedValue

End Sub

Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView1.ItemUpdating

e.NewValues("ddlFund") = CType(FormView1.FindControl("ddlFund"), DropDownList).SelectedValue

e.NewValues("ddlSegment") = CType(FormView1.FindControl("ddlSegment"), DropDownList).SelectedValue

e.NewValues("ddlAssetCategory") = CType(FormView1.FindControl("ddlAssetCategory"), DropDownList).SelectedValue

e.NewValues("ddlAssetSubCategory") = CType(FormView1.FindControl("ddlAssetSubCategory"), DropDownList).SelectedValue

End Sub

SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Inserting

Dim cmd As SqlCommand

Dim con As SqlConnection

Dim InsertTransaction As SqlTransaction

cmd = CType(e.Command, SqlCommand)

con = cmd.Connection

con.Open()

InsertTransaction = con.BeginTransaction

cmd.Transaction = InsertTransaction

End Sub

Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted

Dim cmd As SqlCommand

Dim InsertTransaction As SqlTransaction

Dim iID As Integer

cmd = CType(e.Command, SqlCommand)

InsertTransaction = cmd.Transaction

cmd.CommandText = "SELECT @@IDENTITY AS [ID]"

iID = CInt(cmd.ExecuteScalar())

InsertTransaction.Commit()

Dim paramID As New ParameterparamID = SqlDataSource1.SelectParameters.Item("ID")

paramID.DefaultValue = iID.ToString

FormView1.ChangeMode(FormViewMode.Edit)

FormView1.DefaultMode = FormViewMode.Edit

SqlDataSource1.DataBind()

End Sub

End Class
0
Rowena
3/10/2009 9:00:36 PM

 Hi

If you want to do something in pageLoad then you can use the same function which is available as an event in asp.net ajax client side framework ie 

 <script language="javascript">
function pageLoad()
{
alert("Hii");
}
</script>

alerts the text "hii" during the pageLoad event . Here you can do the custom logic in client side which you want to do during the pageLoad event .


Regards
Pawan Mishra
“The greatest compliment that was ever paid to me was when one asked me what I thought, and attended to my answer.” - Henry David Thoreau
0
Pawan_Mishra
3/11/2009 6:51:01 AM

Hi Pawan,

This isn't my problem. I have the pageLoad event working, it just doesn't work correctly. The problem I am having is that the cascading dropdowns take time to fill and the pageLoad event is fired before the dropdowns are filled. The way I have gotten around this is to put in an alert so it pauses the pageLoad event and gives the dropdowns time to fill, then I set the value. I want to take out the alerts, but then the code doesn't work. So I need to figure out where I should put my code, instead of the pageLoad event.

 If you have any suggestions for solving my issue they would be greatly appreciated.

 Thanks!

0
Rowena
3/11/2009 5:56:39 PM

Hi,

beginRequest and endRequest only fire when i click a button on the page, not when the page is loading. I need to set the value when the page is loading. Any ideas where about in the code I should set the value?

 Thanks!

0
Rowena
3/11/2009 6:17:08 PM

I still need help on this problem. Perhaps I am going about it the wrong way. I will try to describe again what I am doing.

I have a page where a user enters search criteria, then they hit search. It takes them to a new page with the controls filled with the appropriate values based on a query to the database. The controls are populated in the pages Page_PreRenderComplete event.Everything works except I have tried to make two of the dropdowns CascadingDropDowns. When Page_PreRenderComplete fires the CascadingDropDowns haven't actually been populated, so setting the SelectedValue doesn't work. Where should I set the SelectedValue?

 I have posted my code already in the thread.

 Please help!

 Thanks in advance.

0
Rowena
3/16/2009 9:03:38 PM

 You can set the value for the dropdown while editing is by using the property for cascadingdropdown of

SelectedValue.

Something like this..

CascadingDropDown1.SelectedValue = <the value that you want to bind >

use this when you are binding the data in edit.

Hope this works for you.

Thanks

 

0
dreamalong
4/2/2009 2:23:36 PM

I can see that most folks aren't understanding your problem. I do, but I have the same problem.

More siimply: Does anyone out there have a .Net 3.5 real business application using AjaxControlToolkit CascadingDropDowns that sets the initial value of the cascading dropdown group from the page load event. (note: we know how to load the dropdowns and we know how to set the value of a normal dropdown, but the problem occurs when you want to default the values from the page load for the AjaxControlToolkit.CascadingDropDowns - you have read the initial values from a customer record in the database or you have passed in the values from a search screen)

0
rstevens99
4/8/2009 5:36:06 PM

Thanks for clarifying my question for me!

0
Rowena
4/8/2009 6:31:09 PM

I got it working, seems pretty simple now (I hope!)....  Remove the Text property from the DropDownList condtrol and add SelectedValue property to the CascadingDropDown extender.

<asp:DropDownList ValidationGroup="main" ID="ddlAssetCategory" runat="server" DataTextField="AssetCategory" DataValueField="AssetCategory" Text='<%# Bind("AssetCategory") %>' AppendDataBoundItems="true" DataSourceID="SqlDataSource4" />

<asp:DropDownList ValidationGroup="main" ID="ddlAssetSubCategory" runat="server" DataTextField="AssetSubCategory" DataValueField="AssetSubCategory" Text='<%# Bind("AssetSubCategory") %>' AppendDataBoundItems="true" DataSourceID="SqlDataSource5" />

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlAssetCategory" Category="AssetCategory" PromptText="Please select a category" LoadingText="[Loading categories...]" ServiceMethod="GetAssetCategories" ServicePath="AssetManagement.asmx" BehaviorID="CascadingDropDown1" SelectedValue='<%# Bind("AssetCategory")%>' />

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddlAssetSubCategory" Category="AssetSubCategory" PromptText="Please select a subcategory" LoadingText="[Loading subcategories...]" ServiceMethod="GetAssetSubCategories" ServicePath="AssetManagement.asmx" ParentControlID="ddlAssetCategory" BehaviorID="CascadingDropDown2" SelectedValue='<%# Bind("AssetSubCategory") %>' />

0
Rowena
4/24/2009 4:48:35 PM
Reply:

Similar Artilces:

how to get selected the value of cascading Ajax dropdownlist extendar control after postback.
how to retain value of dropdown list after postback which is extended by ajax cascading dropdownlist extendar. thanks in advance.     Hi, Can you further elaborate your problem? your retain value is for nxt drop down list? how many drop down list you have? normally what we trying to retrieve value from selected dropdown value is Label1.Text=DropdownList1.selectedValue :) Regards, Hideyoshi, hi,i have 2 Ajax dropdownlist Which is filed through web service. one filter the other.the second dropdown has value <-All->,a,bwhen i select a and cl...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {            // obtain category id and name            categoryId = productCategories.Rows[i]["CategoryId"].ToString();            categoryName = productCategories.Rows[i]["Name"].ToString();            // populate the list boxes            categoriesListAssign.Items.Add(new ListItem(categoryName, categoryId));        }   ddl button click    protected void assignButton_Click(object sender, EventArgs e)    {            //Request the product ID from the query string            string pr...

How to take selected value of dropdownlist in web method using cascading dropdownlist
Hi All,I am using C# asp.net 2.0 and ajax1.0.I am trying to fill dropdownlist using ajax cascading toolkit but I am not able to populate the dropdownlist.  My question is how do I take input value of parent dropdownlist in web service the fill the data that is in my senario I have subprod parent (fill on page load) and then Prod fill on subprod selection.  The web service method I used is  public CascadingDropDownNameValue[] GetProd(string knownCategoryValues, string category) { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(known...

how to get SELECTED VALUE of parent dropdownlist to target dropdownlist using cascading
Hi All, I am using C# , asp.net2.0 , Ajax1.0 i am filling dropdownlist using cascading ajax extender. i taken help of ajax site and build a code to fill the control. my question is how do i get parent selected item value. my web service code to fill target value public CascadingDropDownNameValue[] GetProd(string knownCategoryValues , string category) {StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //string subgrp ; //int sub1; //if (!kv.ContainsKey("Prod") || !Int32.TryParse(kv["Prod"], out sub1)) //// if (...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

VB.NET
I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateCommand="dgMeds_UpdateRow"     OnCancelCommand="dgMeds_CancelRow" AutoGenerateColumns="False" Visible="False">     <Columns>         <asp:BoundColumn DataField="medid" ReadOnly="True" HeaderText="MEDID"></asp:BoundColumn>         <asp:BoundColumn DataField="subjid" ReadOnly="True" HeaderText="Subject ID"></asp:BoundColumn>         <asp:BoundColumn DataField="visitnum" ReadOnly="True" HeaderText="Visit #"></asp:BoundColumn>         <asp:TemplateColumn HeaderText="Medication Type">             <ItemTemplate>                 <%# DataBinder.Eval(Container.DataItem, "medt...

Cascading Dropdown - Initially selected value
Hi there, I am having an issue with a pretty basic problem. I have managed to get the cascading drop down lists working ok with information coming from a database. On the initial page, I need to have a value in the drop down list already selected, i.e. the current year in one drop down and current month in the next. The information from both of these is sent to a query to output a datatable. Can anyone help with this? I'm not sure I understand the scenario, but I think the new CascadingDropDownNameValue(..., defaultValue) constructor may be just what you're looking for. (First available ...

dropdownlist's selected index value is not printing the selected value
Here iS my code .Aspx Page <asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >   </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" /> my aspx.cs protected void Page_Load(object sender, EventArgs e) { fillddlkeyword(); }protected void Page_Init(object sender, EventArgs e) { ...

DROPDOWNLIST DOES NOT SELECT THE SELECTED VALUE
Hi all, i am using C# , asp.net vs2005. ajax 1.0 i am populating data programitically . when i select first value, dropdown control select the same. when i select second value ,dropdownlist select second value too But i does not continue  from third value onward . when i select third value, dropdownlist control select second value then after behavior reman the same no matter what i select dropdownlist control select second value ONLY.<asp:DropDownList id="Ddlzse" runat="server" Width="165px" Font-Bold="False" Fo...

Fail to get selected value of a DropDownlist in Ajax
Hi there, In my Ajax code, I have an employee list. If an user selects an employee,his/her info will show up on an updating form below to allow the emp info to be updated. after the updating button click, all fields(TextBox) are updated successfully, but a selected value in a dropdownlist control fail to update.Does anyone know what should I do to solve this problem? Thanks! BTW, after updating, I use the "Response.Redirect" this page to update the above employee list. If I use "Server.Transfer" it would cause a "Sys.WebForms.PageRequestManagerPars...

HTML.select (UI helper) how to build a select list with value not equal to the display value
Hi Guys, I have a newbie question on HTML.select (UI helper). One of the tutorial I have come across shows the following: "string [] SelectList = new string[]{'Apple', 'Orange','Mango','Banana'};" "Html.Select('FruitList',SelectList)" it will give me:value = "Apple"  "Apple " However, I would like to have the following instead: value = "1"  "Apple " What should I do on the VIEW in order to achieve this? thx, George what you need to do is create a collection to use for your data sou...

AJAX RC1
I have three cascaded dropdowns. I want to select default value for these dropdowns. Is there a way ? From sample I get the impression that web service method gets called on initialization and there is no way to know if dropdown is filled in and ready to select default value. Any thoughts? The SelectedValue property of the CascadingDropDown is documented on its sample page: http://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspxhttp://blogs.msdn.com/DelayThis posting is provided "AS IS" with no warranties, and confers no rights. Yes I know that there is a pr...

Default Value in Ajax Cascading Dropdownlists (fed from DB)
I have successfully managed to utilise 2 cascading dropdowns (data pulled from SQL DB) which are linked and updated using the AjaxControlToolkit.  The 2 dropdowns contain Client Name and then Client Contact Name respectively.  The 2 dropdowns are part of a detail view and successful insert into a database but when I come to edit the information I need to manual selected the values again, i.e. the defaul values on the dropdown are not being set. Does anybody know why perhaps this is the case?  I am using SelectedValue='<%# Bind("clientID") %>' and o...

Form: Focus on selected values in dropdownlists, Refresh after selection and hidding formfields based on selection.
Hello again,I have a form with several dropdown lists. Depending on the selected value in the dropdown lists other fields become available in that same form. It is working in classic ASP in combination of JavaScript. I want to migrate it to ASP.NET. I have posted a part of the form at the end of this post.My questions:1. I use <option <%If iFood="0" then%>selected<%End If%> value="0">No value selected</OPTION> to select the selected item when the form is reloaded after the selecting. I know that this also works in ASP.NET, but isn't there a typical ASP....

Cascading Dropdown Selected values and Default values
I am loading the cascading dropdown control with data from my database implementing web service methods written in VB, and cascading dropdown control runs fine. Now as in any classic application I would like giving default values to  3 dropdown lists concerned with cascading and also getting back selected entries to call my database to retrieve records with values read as criteria. First I tried to postback with a button control after selecting entries in cascading dropdown control, but the resulting selected values are empty. Can anyone help. Hi, As you click the Button...

Handling DBNull Values in DropDownList Selected Value
I have a dropdown list inside a formview that is used to update a business opportunities table. Each opportunity may or may not have a salesperson assigned. On the update page I want to set the current value in the database as the selected value in the dropdown list. But if there is no salesperson assigned i need to handle the dbnull value and not try to set the selected value. Can someone give me some pointers? Should i handle this in the Formview_databinding event or in the Datasource for the opportunity Databinding event? How do i get at the cell of the datasource that i need to test for ...

DropDownList value selected base on database value?
Hi, is there anyway how I can allow my dropdownlist (on pageload event) to select the value base on the value found in the database, in addition I also want the dropdownlist to contain other values too however the selectedValue must be the one found in the database. Sorry if it sounds confusing. I'm using VB.NET 2003 with ASP.NET Thanks. Hi,Whatever you want to get selected for your dropdown use following code.if(dropdownid.items.findbyvalue("value") != null){    dropdownid.items.selecteditem = false;    dropdownid.items.findbyvalue("value").selected = t...

Select a option dropdownlist and show values in field , dont load the page .. Javascript o Ajax
Hi Friends,  I need to select a option dropdownlist.... With the selected option look at in preload table may be, Look at record and show values at others field, Not load the page (Javascript , Ajax ??' ).one thing more, Can I write on dropdownlist and look at into the dropdowlist??? Thank You So Much, Im Sorry my english is very bad......   Put AutoPostBAck="True" for the DropDownlist, and in the dropdownselectedindexcahnged event Get the selected values as DropDownname.SelectedItem.Value == > ...

Text value not changing when new value on DropDownList selected
Hi, I am looking for assistance on how to correctly post events when a new item is selected on a drop down list. My drop down list has autopostback enabled and a sub routine associated with SelectedIndexChanged. This routine is activated when another entry in the drop down list is selected, however, the value is not changed and the drop down list returns to the originally selected value. For example, if I have 2 values in my drop down list, 0 and 1, and 0 is the currently selected value. Selecting 1 will trigger the event but the drop down list will return to displaying 0 as the selected value. Even looking at DropDownList.Text in debugger the value is not changing from 0 to 1. By turning off AutoPostBack the event is not triggered. Can anybody give advice on what I need to do to correctly trigger an event when the value of a drop down list is changed?  Thanks. Sounds like your initial Data binding method(s) are getting called again. Are you using the IsPostBack check before calling those methods? If IsPostBack = false then     BindData End IfChris LoveASP.NET 2.0 Your Visual Blueprint for developing Web Applications  where do you populate your DDL?Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET I wasn't using IsPostBack, should I be? Drop Down List has fixed values set using the Edit Items option, but the selected value, when the ap...

dropdownlist
i have created a dropdown list that is populated from a sqlserver datasource. i have a separate sql command which uses the dropdownlist.selected value as a parameter and returns the command value to a label.  it mostly works fine but with one problem. when the page loads, the label value is null, because it doesn't seem to treat the dropdownlist default value as a selected value. when i use the dropdownlist to select a value, this is fine and the label begins to display the expected value. is there anyway I can make the default value when the page is loaded act like a manually selected value, so the label control never displays a null value?  Can you post you code...If your requirement is to Insert your own Item at the top and mark it as selectyed then here is the code  ddlType.DataSource = objclsReservation.getTitles(); ddlType.DataTextField = "str_Title"; ddlType.DataValueField = "pk_TitleId"; ddlType.DataBind(); ddlType.Items.Insert(0, new ListItem("Please Select", "0")); If you want to select a value alrady exist in your records then use this piece of code   string strMemberTitle = ObjMember.Title; // Write your value to be selected for (int i = 0; i < ddlMembership.Items.Count; i++) { if (ddlMembership.Items[i].Text.Equals(strMemberTitle)) { ...

Assigning value from dataset as selected value in cascading dropdowns
hello!  I have successfully implemented the Ajax Cascading Dropdowns but am running into an issue.  I am databinding the available selections to all three of my dropdown lists.  Then I need to make the selected value of each dropdown a value from my dataset.  The selected value works for the first dropdown, but I cannot figure out how to set up the selected values of the other 2 dropdowns.  (This would be values a user has selected previously, not default values.) Can anyone assist me? Thanks in advance!   Hi Stormcadi, As far as I know,  you should d...

Based on selected value from HTML.Dropdownlist, the values to be fetched
Hi,  I'm using Html.DropDownList.  When selection within this box changes, I need to retrieve the values from table based on the selected id(datavaluefield) of dropdownlist. Here my code ViewPost.cs viewpage <%=Html.DropDownList("CategoryID",ViewData["CategoryID"])%>  ---- based on selected value from the user the below table should fetch the value the db <table>        <tr>                   ...

Grdiview, 2 dropdownlist, how to change values in Dropdownlist with Ajax
 Hi,  first of all, I'm new to AJAX and searched a lot about my topic, but couldn't find anything.  Let’s describe my situation: I'm writing a Web application to manage the work schedule of the staff. Basically I have a table filled with date, project, subproject, time and additional description. All the data is stored in a mysql database. To show the data I use a Gridview, in this GridView I have two depended dorpdownlists (DDL). If the value of the first DDL changes the content of the second drop dwonlist need to be updated. (Each project has its o...

Change value of textbox based on value from dropdownlist using ajax?
Hello, I want to program an aspx form so that depending on what value you select from a dropdownlist, a textbox gets populated using ajax or javasciprt (client based) I did this already server-side by reading from an SQL data table, but it's annoying because of the page refresh, anyway to do the same thing using ajax or javascript? Look at my code below:   Many thanks ! :)   Sub ddllocations_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddllocations.SelectedIndexChanged Dim strconn As String Dim myConnection As New SqlConnection(strconn) ...

Web resources about - Cascading Dropdownlist - setting selected value - asp.net.ajax-ui

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 3/21/2016 9:11:13 AM