change dropdownlist's selected value on textbox change

Hi there,

I have one dropdownlist and textbox in template column of gridview. Now whenever grideview is in edit mode user can change textbox and dropdown value. Now I want to set dropdownlist's selected index to 0 when user enter any value in text box using javascript. i m new to javascript. Is there any idea to implement this?

1
meghnamakadia
3/3/2009 6:17:07 AM
asp.net.client-side 24353 articles. 1 followers. Follow

10 Replies
4866 Views

Similar Articles

[PageSpeed] 56

Check this out.

 

var ddl = document.getElementById('<%#dropdownlistname.ClientID%>');

ddl.selectedIndex = 0;

 

 


Thanks,
santosh_maharaja

Please mark as answer if you got expected solution.
1
santosh_maharaja
3/3/2009 9:47:16 AM

this way

protected void gvw_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType.Equals(DataControlRowType.DataRow))

{

DropDownList ddl = (e.Row.Cells[N].Controls[N] as DropDownList)

Textbox txt = (e.Row.Cells[N].Controls[N] as TextBox)

txt.attributes.add("onkeypress",string.Format("document.getElementById('{0}').selectedIndex=0",ddl.ClientID))

}

}


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
1
shashankgwl
3/3/2009 9:58:18 AM

hi,

add javascript function to the text box onblur event with this as argument.

In that function now you can access the textbox control and at the same time you can change the dropdown selected value.

 

Mark as ANSWER if you got the solution from this post. 


Regards,
Ravi Kishore.Ch

Mark as "ANSWER" if you got the solution from this post.
0
chravikishore
3/3/2009 10:00:09 AM

 Hi

 I put the below code in textbox valuechange event  

document.getElementById(comboBoxName).selectedIndex=0;

Its working fine but when i accessed this row in codebehind and try to get combobox's value it always gives the old value not 0 tht i changed thru javascript.

I think it does make sense to u. what's my problem.

Could u please help me to solve it.

Thanks.

0
meghnamakadia
3/3/2009 11:56:48 PM

 

 Hi

 I put the below code in textbox valuechange event  

document.getElementById(comboBoxName).selectedIndex=0;

Its working fine but when i accessed this row in codebehind and try to get combobox's value it always gives the old value not 0 tht i changed thru javascript.

I think it does make sense to u. what's my problem.

Could u please help me to solve it.

Thanks.
0
meghnamakadia
3/3/2009 11:57:32 PM

Can you elaborate more on your problem...

Default value is selected first when textbox does not have anything. Lets say now user changed dropdownlists value. And now user enters something in textbox and your dropdownlist is resetting due to my given code. Is this your scenario...

If yes then Now you are accessing which value and getting what...

If you give your example with values containing in dropdownlist, it will be good.

 


Thanks,
santosh_maharaja

Please mark as answer if you got expected solution.
0
santosh_maharaja
3/4/2009 3:53:05 AM

 My scenario is like below.

In Edit mode of gridview Dropdownlist is having selectedindex value like 3 and when user enter some value in textbox selectedindex of droupdownlist should be 0. I did it thru javascript it was working fine but when I press save button and access this row and dropdownlist in my codebehind it shows selectedindex 3 instead of 0.

I got solution. The problem is with disable I used below code

document.getElementById(comboBoxName).selectedIndex=0;

 document.getElementById(comboBoxName).disable=true;

now i removed disable line and its working fine.

I dont kow how it related with disable property.

 

 

1
meghnamakadia
3/4/2009 5:20:32 AM

isn't it the same what i told u?

this line didn't work coz it is wrong.  document.getElementById(comboBoxName).disable=true;

the line above should be rewritten as

 document.getElementById(comboBoxName).disabled='disabled';


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/4/2009 5:29:38 AM

shashankgwl:

isn't it the same what i told u?

this line didn't work coz it is wrong.  document.getElementById(comboBoxName).disable=true;

the line above should be rewritten as

 document.getElementById(comboBoxName).disabled='disabled';

Not necessarily. If you disable a server-control, it will not hold the new value on PostBack.

NC...

 

0
NC01
3/5/2009 6:56:02 PM

Can't spoon feed someone, this was her post in question.

My scenario is like below.

In Edit mode of gridview Dropdownlist is having selectedindex value like 3 and when user enter some value in textbox selectedindex of droupdownlist should be 0. I did it thru javascript it was working fine but when I press save button and access this row and dropdownlist in my codebehind it shows selectedindex 3 instead of 0.

I got solution. The problem is with disable I used below code

document.getElementById(comboBoxName).selectedIndex=0;

 document.getElementById(comboBoxName).disable=true;

now i removed disable line and its working fine.

I dont kow how it related with disable property.

THE WAY SHE WAS TRYIN TO DISABLE THE COMBO WAS NOT POSSIBLE, WHICH I POINTED OUT


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
3/6/2009 4:10:43 AM
Reply:

Similar Artilces:

How to change the dropdownlist's value from database on selection of 1 st dropdownlist
Hi Friends, I have 2 dropdownlist. 1 for country and 1 for state. When i will select any coutary according to that all state related to that countary shoud change in dropdownlist. I have to fatch both dropdownlist's value from sqlserver database. And i also don't know how to make relationship to get all value in aspx page. so please also tell me what should i made in database means primary foreign key concept. I will be very thankful if you can send me code for that.    There will be 2 tables in the database, Country with country_id as primary key. Another table Stat...

On selection changed in dropdownlist, change a textbox
Newbie: VS2008  Have a FormView, which includes a textbox and dropdownlist controls. The dropdownlist control is bound to a datasource. On SelectionIndexChanged event of the dropdownlist I need to pouplate the TextBox with certain text. How can I do it? Can you post your code please?  There's several ways to handle it, and I'd like to point you in the direction that closely matches your existing code.If this post helped you, Mark As Answer.  Set your dropdownlist autopostback = true.In the selected index changed event: First You have to find your controls firs...

superreview cancelled: [Bug 244761] Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected : [Attachment 149378] Change the check for if the dropdown is show
Simon Paquet (back in business) <bugzilla@babylonsounds.com> has cancelled Doron Rosenberg (IBM) <doronr@us.ibm.com>'s request for superreview: Bug 244761: Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected http://bugzilla.mozilla.org/show_bug.cgi?id=244761 Attachment 149378: Change the check for if the dropdown is shown to the correct way http://bugzilla.mozilla.org/attachment.cgi?id=149378&action=edit ------- Additional Comments from Simon Paquet (back in business) <bugzilla@babylonsounds.com> ...

superreview requested: [Bug 244761] Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected : [Attachment 149378] Change the check for if the dropdown is show
Doron Rosenberg (IBM) <doronr@us.ibm.com> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 244761: Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected http://bugzilla.mozilla.org/show_bug.cgi?id=244761 Attachment 149378: Change the check for if the dropdown is shown to the correct way http://bugzilla.mozilla.org/attachment.cgi?id=149378&action=edit ...

Changing textbox.Text value when dropdownlist changes
I figure this should be really simple. Here's what I want to happen: Page loads first time, textbox is blank. User changes dropdownlist to a certain value. Page refreshes and changes textbox.text to dropdownlist.SelectedItem.Value but keeps the value of any other textboxes that might've been changed by the user. I can make this work fine when it's just dynamic (non asp.net generated) text in the page. Thanks. hello, there is the OnSelectedIndexChanged which you should define,in that method you set the value of the textbox as follows: txt1.Text = ddl.SelectedItem.Value; ...

to change value of Client Side Select html control from database value....
hello forum,  I have a select .. Demo.aspx <select id="DropAccType" name="DropAccType"> <option>Select</option> <option>Saving</option> <option >Current</option> <option>Regular</option> <option>Demat</option> </select> I want to set the value of select by fetching the data from daabase i.e. In my table if I have Value current then when i request the demo.aspx then in select Control the value Current should get selected..... Please help me to sort this out...   Thnx in advance.. Hi-I could be...

User's Name Changed
We are using Groupwise 5.5 I have a user that recently married. I have created a Groupwise alias for the new name, but how do I go about changing the Groupwise Object/User ID and NDS account ID and keep their email account intact? Thanks, J.Jensen Jeff, you can simply rename the Groupwise account. No mail loss. Uwe -- Novell Support Connection Volunteer SysOp Please don't send me support related e-mail unless I ask you to do so. ...

I want to display textbox on changing value of dropdownlist or selected value of dropdown list.How could i?
for example i have taken field PF%,PF($)  in dropdown.Onselected value of % i will show textbox.In which u can fill  the value of PF% based on that calulation will be shown in other textbox. But how can i do thta? Not too sure I undertand your question, but if you want to show/hide elements here's a few things you might want to try: You can set the dropdown's autopostback to true and perform all sorts of wonderful serverside stuff, including adding a textbox control (with a certain value) to a container div. If you want to keep things light then use some CSS and ...

how to change the value of checkbox when i change the value of textbox
i want the checkbox to change its value to unchecked when the textbox doesnot have anything i.e is value is "" and as soon as i enter anything to it, the checkbox should automatically change to checked. Can you please tell me how to do this Add to the textbox: OnKeyUp="CheckValue()" Add to the html: <script language="javaScript"> function CheckValue() { if (document.getElementById('textboxid').value.length == 0) { document.getElementById('checkboxid').checked = false; } else { document.getElementById('checkboxid').checked...

DropDownList Selected Index changed
I have 2 dropDownList, let call them dropA and dropBI have also a textBox called txtImpact.The dropA contains 5 items: "ItemA"... "ItemD"  and a default Item called " not selected" its value is "-1" and the value for the itemA is "1", the value of the itemB is 2 ...The same thing is in the dropB, except it has 6 items, "item1" ... "Item5" and a default item called " not selected" its value is "-1", the values for the others are from 1 to 5.Ok the problem is:I want to create a clide side events, no...

Change Event not fired when changed once or more then restored to it's original value.
Hi. I am trying to ATLAS-ize an existing application with lots of Master Detail controls. As I don't want to write a heap of new code I am using UpdatePanels rather than writing web services even though my situation is similar to the one in the CascadingDropDown example (http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx) The problem I have though is that if I change the master listbox selected value (say from 0 to 1) then the Update Panel refreshes fine. If I change it back from 1 to 0 the SelectedIndexChanged event does not fire leaving a load of incompatible in...

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) { ...

how ontextchanged event in datalist fire and when that textbox value change than another textbox inside datalist value also change
 i have one datalist into which i used maskededit extender for time entry there is three textbox (1) start_time (2) end_time (3) duration so when enter  end_date value than this text box ontextchage event fire and duration will automatically calculate by(end_time - start_time) and display into datalist duration textbox. in datalist there is more than one item.i put some code so just check  <asp:DataList ID="CONTRACT_SERVICE_ITEM" runat="Server" RepeatColumns="1" RepeatDirection="Horizontal"      &nbs...

changing and reading a disabled textbox's value
Hi, I have a disabled asp textbox on a page.  I use a javascript function to display a value in there when a certain event occurs (onBlur).  The value is displayed on the event, however it's not retained.  I don't know how to explain this, but the disabled textbox will show an updated value of 2.00 for example after the javascript event, but if you look at source, the value will still be 0.00 which it was when the page loaded.  Also on postback, I need to read the value, and it still gives me 0.00 on the asp.net side.  I don't know how a browser can ...

How can I handling dropdownlist value changed on client side
Hi,I want to verify that the user really meant to change a field that is displayed as a drop down list, but only part of the time based on the original value of the field.  For performance reasons I prefer to do this with javascript on the client.  However, I cannot figure out how to wire you a client side event handler for the value changing. I was hoping to be able to use the OnChange event of the underlying Select. Any thoughts? jerry Hi you can use a CustomValidator1  and ClientValidationFunction="yourjavascript function"   <asp:Drop...

.NET changing ID's on elements created in the code behind file. How to change that?
 Hello everyone.First of all i'm using nested masterpage for my blog.aspx file, and i'm concerned that ASP "needs" to change the ID's so it can keep track of whats going on in nested Masterpages  (or so im told :P) . I create a UL element from code behind file with the ID = ContentNavList and my CSS file has a style for that ID, but .NET changes the ID when the page is rendered to something like this:   1 <ul id="ctl00_ctl00_defaultPCH_NavigationContentPCH_contentNavList">  Is it possible to change that behaviour? Otherwise i...

Changing a textbox value by changing 2 other textboxes inside of a FormView
Ok...here goes.  I want to be able to dynamically change the value of a textbox by changing the value of 2 other textboxes.  I have 4 textboxes, txt1, txt2, txtDB, and txtTotal.  These are all inside of FormView1 which is inside of UserControl1.ascx which is inside of UserControl1.aspx.   The goal is to have txtTotal read the summation of the 3 other textboxes.  txtDB has a bound value read from a database (why it is in a FormView).  txt1 and txt2 can be changed.  I want though, for the txtTotal textbox to change in real time wit...

Change value of textbox dependent on value from dropdownlist
How do you achieve this but client-side, to avoid the constant page refresh? (Javascript)   Best, Asaf. You need to use an onChange event on your DropDownList and wire it to a JavaScript function. In the code example below, ddlID and txtID are the control IDs of your DropDownList and TextBox controls. Code: ddlID.Attributes.Add("onChange", "setText('" + ddlID.ClientID + "', '" + txtID.ClientID + "');"); JavaScript: function setText(ddl, txt){   var ddlID = document.getElementById(ddl);   var txtID = document.getElementById(txt);   &...

How to change SQL stament on client side clientdatset.commandText:='Select.
Iam testing DataSnap 2009. In Server Side I set allowCommandText property of provider to True. In classic application this will allow to change comandtext of clientdataset when I need. With datasnap 2009 i need to do anything more to do de same. In cliient side if I try to change dlientdatasets commandText property When I close/Open clientedataset the result set dont change- ¿I need to change SQL stament in clientdataset?,¿is this possible with datasnap 2009? ¿How I do this? Edited by: hilario bethencourt on Oct 5, 2008 12:23 PM Same problem here. ...

change menu's property Target in client-side (javascript)
Hi all ! I need to be able to change the target of my menu (regular asp.net control) in client-side using javascript. Does anyone have a clue or tip? Thanks a lot !We are here to learn, and teach whenever possible... Since every server side control renders finally as HTML, you must be able to access each HTML element rendered using javascript and do any changes but, I did not understand what Menu target means. other than that you can view source to see how the Menu control is rendered and use js to modify any part thereof. Thanks,RavikanthPlease "Mark as Answer&q...

Custom paging and DataGrid's PageSize value change through dropdownlist control
I'm implementing custom paging for a datagrid through an asp.net dropdownlist control that postback the new pagesize. It looks like: protected void ddlRecordsPerPage_OnSelectedIndexChanged(object sender, EventArgs e) {             this.dgLocations.PageSize = Int32.Parse(this.ddlRecordsPerPage.SelectedItem.Value); } But upon the page reloading, the old pagesize is what loads on not the new one.  Only when I do a postback again does the new pagesize take effect. I know many would recommend that I do something like BindData() ...

Changing control's selected value with viewstate before page is delivered back
This should be an easy thing to do, but I have yet to make anything work. I have three dropdown lists. Each one is a different method for searching a database, such as color, size, type.. A user selects a dropdown (say color) and selects a value from that dropdown (say red) and a OnSelectedIndexChanged fires and autopostback's to do the search and return the results. All this works fine except that when the results return the dropdown used shows the value the user selected (red). I want any dropdown used to be reset to the "first time loaded" value of  "select". I've tried to...

Can you change a linkbutton's text using client side javascript?
I have a linkbutton which opens a new window. When the user closes the new window, I want to change the text of the original linkbutton. The issue isn't the popup window since know how to use window.opener. The problem is that I don't know how to use javascript to change the inner text of the linkbutton which I know is rendered as anchor tags. Any suggestions? Hi, on the Page where the LinkButton is, you can output the client-side ID of the LinkButton with it's ClientID property assuming you have <asp:LinkButton ID="LinkButton1" runat="server" Text="Hello" />So you could ou...

Need to enable a button when radio list's selected value changes
Hi,I have an update panel that loads a radio list with a particular value selected.  There is then a button called "update" that is not enabled (greyed out).My task is to enable the update button when the user changes the value.Right now, I postback to the server; but we have things setup in such a way where it isn't a good idea to postback.Is there a way to handle this on the client side?I'm new to client side development; I know how to add handles and interact with the DOM using Microsoft's abstraction API, but I can't quite see how a) to make the client scri...

Web resources about - change dropdownlist's selected value on textbox change - asp.net.client-side

Resources last updated: 2/17/2016 4:06:55 PM