Based on my dataset row value , my drop drown will focus the particular list item in page load event.
ddparty.SelectedIndex = ddparty.Items.IndexOf(ddparty.Items.FindByValue(ds.Tables[2].Rows[0][1].ToString()));
i try the above code its not working.
Setting the property:
mydropdown.SelectedItem
or
mydropdown.SelectedValue
Make sure you do this AFTER databinding the dropdown control.
Don't know if you've set your DataValueField to the datatable's second column. On the other hand if you've set your DataTextField to it, try FindByText instead of FindByValue.
As a side note, try to quickwatch in the debugger, the value of the index you get.
Related
I have a details view that is in "insert Mode" so the user just sees blank spaces to enter values. I have two drop down lists and I wanted to have the second ddl change its value by what was selected in the first ddl. I tried setting ddl1 to a label so ddl2 would change when the label changed. The problem I am having now is that I need autopostback to update the value of the label, but selecting "autopostback" on the ddl1 makes my code throw a data binding error.
I was wondering if there was any way I could get around using autopostback and still update values selected in the first ddl to the label.
Thank you.
Try using AjaxControlToolkit. It has a feature to cascade ddlists. Use updatepanel as container for both of ddls so you can omit autopostback.
Your query is not completely clear. But if you want to change the dd2 value on change event of dd1, you can use the following code:
$("#<%= statusDDL.ClientID %>").val($("#<%= dd1.ClientID %>option:selected").text() );
It is not clear whether you want value or text property.
Also I am not 100% that this syntax will work. But obviously it can be done using this concept searching on net for your requirement
I wish to pass values of the selected items into a database and however noticed that the selected item is not what is sent into the database you can see in the snap shot below.
during run time the following value is recorded.
Where did it all go wrong with the dropdown lists selected item?
Counting on your intelligence...thanks.
Put your call to load the dropdownlist in
if (!Page.IsPostBack)
{
//LoadDropdownListHere();
}
Try DBNull.Value instead of null.
Edit:
I think you need to specify the type using this overload: http://msdn.microsoft.com/en-us/library/cc491445.aspx
CSMDataSource.InsertParameters.Add("CaseID", DBType.Int32, CaseIDDropDownList.SelectedItem.Text);
I found the problem for the dropdownlist always selecting the first value. It appears the dropdown list is always rebinded anytime i click a button that requires a post pack as such the data tha was binded at page load re binds a gain before the selected item gets picked as such the default first value gets picked all the time. to solve my problem i first disabled enable auto postback on the dropdownlist and in the code behind that is my .cs file during the page load, where i first binded the data to the dropdown list, i used a condition like if(!ispostback) to bind my data. what this does is when the page loads first time the dropdownlist is binded and if i should select an item from the drop down list, the "auto post back" that i disabled earlier on keeps the selected item selected and when i click and button that requires a post to the server, the (!ispostback) prevents the dropdownlist to be binded again before selection. so in effect, the selection is done first and afterwards if the page should load anew, the drop down list is binded again.
i was in a bit of a rush while typing so please bare with my typo errors. do call in anytime for more clarification...peace
If we select the dropdown list Item then I want to display the Item Particulars in the Gridview Please Help me
On the SelectedIndexChanged of the dropdown rebind your GridView off of the selected value
Add a dropdownlist control, a button control, a grid view and an sqldatasource.
Configure the datasource first in sqldatasource.
I would recommend write a storeprodure to fetch data into the gridview (sqldatasource).
Bound the parameter to "controls" and select the dropdownlist. Now your DDL is bound to the gridivew. In his table click on advance properties and change property convertemptystringto null = false. (there property is something similar).
If you want a button to update the grid view, do this. Add the default event control to the button, put no code in it.
If you want to change the grid view content based on select directly then choose autopost on selected changed in properties of the DDL.
If everything is fine, this should populate your grid view based on contents in DropDownlist
Using C#, say you have a ComboBox that has a DropDownStyle set to DropDown (there are items in the drop down but the user can manually enter a value as well). How do you set a default value for the ComboBox that is not in the list of values in the drop down, but begins with text from a possible selection? Normally setting ComboBox.Text works fine, but if there is an item in the drop down that begins with the text you want as the default, it automatically selects the first item in the list that starts with the text. For example:
Values in the drop down:
c:\program files\
c:\windows\
d:\media\
Default Value Assignment
myComboBox.Text = "C:\";
Result
Initial value of ComboBox when the form opens is "c:\program files\".
So what am I doing wrong? How do I correctly set a default value of an item not in the drop down list that begins with a possible selection?
Does the following code work?
myCombo.SelectedIndex = myCombo.FindString(#"c:\");
Note: I haven't tried it. Looked up for properties/methods that could help using reflector.
I couldn't repro the behavior you are describing. Adding the three values via the Items collection and then setting the initial value to "c:\" (you omitted an # in your code sample, by the way) worked fine. My guess is that something else in your code is setting the value of the combo box after you set it.
I was able to get this to work with having the items in the ComboBox be ComboBoxItems (I dont see why this wouldn't work with other types). Set the ComboBox.Text like you are and make sure SelectedIndex = -1 and also you need IsEditable = True.
ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound and displays a value within a textbox. The user is able to change this value, then click on a button where the code behind basically iterates through each DataGridItem in the grid, does a FindControl for the ID of the textbox then assigns the .Text value to a variable which is then used to update the database. The DataGrid is rebound with the new values.
The issue I'm having is that when assigning the .Text value to the variable, the value being retrieved is the original databound value and not the newly entered user value. Any ideas as to what may be causing this behaviour?
Code sample:
foreach(DataGridItem dgi in exGrid.Items)
{
TextBox Text1 = (TextBox)dgi.FindControl("TextID");
string exValue = Text1.Text; //This is retrieving the original bound value not the newly entered value
// do stuff with the new value
}
So the code sample is from your button click event?
Are you sure you are not rebinding your datasource on postback?
When are you attempting to retrieve the value from the TextBox? i.e. when is the code sample you provided being executed?
If you aren't already, you'll want to set up a handler method for the ItemCommand event of the DataGrid. You should be looking for the new TextBox value within that method. You should also make sure your DataGrid is not being re-databound on postback.
I would also highly recommend reading through Scott Mitchell's excellent article series on using the DataGrid control and all of it's functions:
https://web.archive.org/web/20210608183626/https://aspnet.4guysfromrolla.com/articles/040502-1.aspx