.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to Capture a DropDownList Selected Index Change Event

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
I have a gridview that receives data based on selection from a primary dropdownlist object. Works. Within the gridview, there is a dropdownlist whose selected index is based on the query from the primary dropdownlist. Works. Problem. How do I force the used to  change whatever value that the dropdownlist contains after they make their initial selection from the primary dropdownlist; except the default value of "Please make a selection". Gridview, contains a checkbox which drives whether a selected row is inserted into the data base. The databind in done using an ObjectDataSource on the presentation page, not in the code behind.   Thank you.   Ayomide 

View Complete Post

More Related Resource Links

Trap Selected Index change event of listbox using Javascript.

Hi All, This is reagarding listbox selection. I have a list box with multi select option. I want to trap the selected index change event of Listbox through javascript. Item of list box can be selected using Click of mouse and also the keyboard up down key with shift. I tried onclick event to bind the javascript function. It works fine if I select by mouse, but it doesen't work for up/down key of keyboard. Thanks, Naveen

gridview dropdownlist selected indeex change event



I bind the ddl as name column in gridview and age as textbox in the next column.

 void bind()


 SqlCommand com = new SqlCommand("Select id,name from employee", con);

SqlDataAdapter da = new SqlDataAdapter(com);

DataSet ds = new DataSet();


GridView1.DataSource = ds;


SqlDataAdapter da1 = new SqlDataAdapter("select id,name from employee", con);

DataSet ds1 = new DataSet();


for (int i = 0; i < GridView1.Rows.Count; i++)


 DropDownList ddl = (DropDownList)GridView1.Rows[i].FindControl("ddlname");

ddl.DataTextField = "Name";

 ddl.DataValueField = "Id";

ddl .DataSource = ds;




the above coding i fallow but in selelected indexchange event i have to dispaly the age of particular name in gridview.

disable a single intem in dropdownlist or stop the ddl change event for a single item


hello guys,

I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.

any feadback would be appriciable.

Thanks and Regards

Inderjeet Singh Khalsa

Selected to change the background color of the page



As this site, http://www.borfin.com.tr/genel/Default.aspx, How can I change the background color selected pages.

Capture event from HierarchicalDataSource


I have a custom hierarchical data source based on the msdn example (http://msdn.microsoft.com/en-us/library/system.web.ui.hierarchicaldatasourcecontrol.aspx).  An event can be raised in the DataSourceView.  If that occurs, I want to display a message on the web page.

The example is that I have a page with a TreeView control which uses a custom hierarchical datasource.  If the user selects a node that they are not allowed to select, the underlying datasource will throw and error.

I want to capture this and add a message to the page.  The Page_Error event is raised, but there are no eventargs.

Anybody know how to capture such an event? 

An alternative approach, although not quite specific enough, is to set a flag during the datasource load event (indicating the datasource is loading) and test for this flag in the Page_Error routine.

how can i display the selected value of dropdownlist from edittemplate to label from itemtemplate?


I have a detailsview with a dropdownlist in it. the detailsview is connected to a database table(employees having the following fields: id-smallint,name-nvarchar, departmnet-smallint). the ddl is connected to another table (departments with the following fields: id-smallint, departmentName-nvarchar). the ddl is in the edititemTempalte of the department field. My goal is to display in  the itemtemplate the departmentName (the selected value from the edititemtemplate ). How can I do this? Doyou have any ideas?

thanks a lot

dropdownlist javascript change items


I can't find solution for this problem for very long time:

I have dropdownlists in Gridview. I need to dinamicly change content of dropdown on client with javascript. Ok, I know to do that. But the problem is when I send data to server changes in dropdownlist does not see. On server I have  old items. How can I change items in dropdown on client with javascript and than see that items on sever when postback data?


dropdownlist bound to sqldatasource adds items instead of replacing on change



I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:

 <asp:DropDownList ID="ddlMajor" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource1" DataTextField="majortext" 
      DataValueField="majorkey" AppendDataBoundItems="True" AutoPostBack="True">
         <asp:ListItem Value="0">Select Major</asp:ListItem>
<asp:DropDownList ID="ddlReq" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource2" DataTextField="req" DataValueField="admreqkey" 
            AppendDataBoundItems="True" AutoPostBack="True">
                <asp:ListItem Value="0">Sel

How can I change values in mydetailsview_ ItemInserting event

I'm inserting values with detailsview, and I want to modify one of my values and my client should not see it.

This is my detailsview:

<asp:DetailsView ID="dv_InsertTaps" Runat="server" DataSourceID="ds_InsertTaps" DataKeyNames="TapId"
AutoGenerateRows="False" DefaultMode="Insert" title="INSERTAR TAPS" OnItemInserting="dv_InsertTaps_ItemInserting">
<asp:TemplateField SortExpression="TapNumero" HeaderText="N&#186; Tap"><InsertItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("TapNumero") %>' ID="tb_TapNumero"></asp:TextBox>
<asp:BoundField HeaderText="Valor" DataField="TapValor" SortExpression="TapValor"></asp:BoundField>
<asp:BoundField HeaderText="Alta Frecuencia" DataField="TapAF" SortExpression="TapAF"></asp:BoundField>
<asp:BoundField HeaderText="Baja Frecuencia" DataField="TapBF" SortExpression="TapBF&quo

Can't change Gridview row colors or styles in the DataBound event


I was highlighting certain rows in my gridview using code like this in the DataBound event:

        if (e.Row.RowType == DataControlRowType.DataRow)
            int vendorCheck = 0;
            //TODO make this shorter
            if (DataBinder.Eval(e.Row.DataItem, "vendorId") != System.DBNull.Value)

Why does OwnerDrawVariable change the look of a DropDownList?

Hi, I am trying to extend a combobox to allow Enabled / Disabled items. I have everything working, except the look of the the combobox changes when Drawmode is set to OwnerDrawVariable and DropDownStyle is set to DropDownList. Why, and is there a workaround? I have tried the suggestion from this link... http://stackoverflow.com/questions/2891981/net-ownerdraw-combobox-vista-7-themed-dropdownlist/3565005#3565005 Whilst this seems to fix the appearance of the combo, it breaks most of the event code, and the OnDrawItem event, whilst fired, always has an index of -1 in the DrawItemEventArgs. I am using c#, visual studio 2010 and .net4 to create a Winforms application.   Cesare          

dropdownlist - default value is not 'selected value'

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?

ASP.Net MVC Dropdownlist and selected value problem

I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea. Controller Code public ActionResult Edit(int i) {      var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");      ViewData["MST_COUNTRies"] = items; } View Code <p>     <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%> </P>I was able to create a dropdownlist for my MVC project, but the value is not selected as  selected value on the dropdownlist. It just shows whole county list from the first.The value is from database. I tried find it from previous post, but it was quite confusing. Please, suggest me for any idea.Controller Codepublic ActionResult Edit(int i){     var items = new SelectList(db.MST_COUNTRies.ToList(), "COUNTRY_ID", "COUNTRY_NM");     ViewData["MST_COUNTRies"] = items;}View Code<p>    <%= Html.DropDownList("COUNTRY_ID", (SelectList)ViewData["MST_COUNTRies"])%></P>

change tab index by pressing enter button widthout postback

hi .  i have 3 textbox :<asp:textbox id="textbox1" runat="server" text="01" ></asp:textbox><asp:textbox id="textbox2" runat="server" text="02" ></asp:textbox><asp:textbox id="textbox3" runat="server" text="03" ></asp:textbox>  how i can focus on textbox2 from textbox1 by pressing enter button (widthout postback)?

show value in label on textbox change event

I want to show value in label on textbox change event , means when user enter text in text box then this value should display in label  . I am using this:<asp:UpdatePanel ID="UpdatePanel1" runat="server">    <ContentTemplate>     <asp:TextBox ID="TextBox5" runat="server" ontextchanged="TextBox5_TextChanged" AutoPostBack="true"></asp:TextBox>    </ContentTemplate>    </asp:UpdatePanel>========================================================protected void TextBox5_TextChanged(object sender, EventArgs e)     {         ViewState["xyz"] = Convert.ToInt32(TextBox4.Text) - Convert.ToInt32(TextBox5.Text);         ViewState["xyz1"] = Convert.ToInt32(ViewState["xyz"].ToString()) * 100;         lbldiff.Text = ViewState["xyz"].ToString();         lblprofit.Text = ViewState["xyz1"].ToString();     }protected void TextBox5_TextChanged(object sender, EventArgs e)    {        ViewState["xyz"] = Convert.ToInt32(TextBox4.Text) - Convert.ToInt32(TextBox5.Text);        ViewState["xyz1

Get dropdownlist event OnSelectedIndexChange using jquery

I have dropdownlist that located inside a repeater, how can i get OnSelectedIndexChange event of this dropdownlist? i want to use this event to set TextBox value olso inside this repeater, i try this code$("#Table1> tbody > tr ").each(function() { var rowId = $(this).attr("id"); $(this).find("td > #DropDownList1").change(function() { $("#" + rowId + "> TD:nth-child(6) > input[name$='TextBox1']").val("Test"); }); }); But did not work, can anyone please help me?

Fill a Listbox with value selected from a Dropdownlist

Hi, Maybe the question has already be posted, but I didn't find it.I have in my web page two controls: a dropdownlist and a listboxMy goal is to fill the listbox with values from my database depending on what I have selected in my dropdownlist.I wouldlike to use the CascadingDropDown component for that. Is that possible ??(I tried on my own and I get this error messageException Details: System.InvalidCastException: Unable to cast object of type 'System.Web.UI.WebControls.ListBox' to type 'System.Web.UI.WebControls.DropDownList'.I think it's when i tried to fill the listbox with this function:[WebMethod] public CascadingDropDownNameValue[] GetAppliForDomain(string knownCategoryValues, string category) { int domainID; //this stringdictionary contains has table with key value pair of country and countryID StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); if (!kv.ContainsKey("Domain") || !Int32.TryParse(kv["Domain"], out domainID)) { throw new ArgumentException("Couldn't find Domain."); }; SqlConnection con = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend