I have a combobox which is populated by a binding source. I'm trying to get my program to do the following, when the selection is changed it carries out the following command:
dataSetInstance.tbl2.Clear();
oleDbDataAdapter1.SelectCommand.Parameters[0].Value = label2.Text;
oleDbDataAdapter1.Fill(dataSetInstance.tbl2);
As a button the above piece of code works and I get the results I'm after, but using the comboBox1_SelectionChangeCommitted method with the same code it seems I have to select the item in the combo box twice to gain the same results as the code I've used above in a button click.
Many thanks,
Instead of SelectionChangeCommited, try using SelectedIndexChnaged.
Have a look at this sample on MSDN:
ComboBox.SelectedIndexChanged Event
Related
I have a SyncFusion ComboBox dynamically added in SynckFusion:GridControl with following code:
SchoolGrid.Model[rowIndex, columnIndex].CellType = "ComboBox";
SchoolGrid.Model[rowIndex, columnIndex].ItemsSource = itemSource;
SchoolGrid.Model[rowIndex, columnIndex].DisplayMember = "FullDistrictName";
SchoolGrid.Model[rowIndex, columnIndex].ValueMember = "FullDistrictName";
SchoolGrid.Model[rowIndex, columnIndex].CellValue = cellValue;
SchoolGrid.Model[rowIndex, columnIndex].DropDownStyle = GridDropDownStyle.Exclusive;
What I want to achieve is:
1)Items in combobox I want to show in "Gujarat/Surat" format. when
user select any item, the value that I want to be shown is only
"Surat", not "Gujarat/Surat". 2) When user open dropdown list, the
selected item should have focus.
In QueryCellInfo event, I've specified value for this column as "District"- property of my model.
In CommitCellInfo event, I am fetching and assigning the values to model properties. So point 1) is working as required. But I am not able to make point 2) working. I've tried using OnCurrentCellShowingDropDown, GotFocus events, but no luck.
How can I make it working?
We have prepared the sample with your code snippet and checked the reported issue of “Focusing the selected item of ComboBox ”, but we were unable to reproduce the issue. Please find the sample link below:
Sample: GridControl
If the issue still reproduces at your end, please modify the above sample to reproduce the issue and update us with the replication procedure. So that we will be able to analyze the issue better and update you with better solution.
I am using a linq to sql for populating a combo box. to populate combobox i am using the following code on page load event:
ColdStoreDataContext csdc = new ColdStoreDataContext();
comboBox1.DisplayMember="Name";
comboBox1.ValueMember="AccountHeadId";
comboBox1.DataSourse=csdc.SupplierPurchase;
the above code is working properly but when I use the given code:
comboBox.SelectedValue="KAMAL SINGH S/O AJEET SINGH";
then it does not properly works means comboBox displayed null value.
Please help me to resolve this problem.
Your combo box has AccountHeadId as its ValueMember. When you set the combo box's SelectedValue, the box will look in its data source for an item whose AccountHeadId matches the value you just set to SelectedValue.
Try
comboBox1.SelectedValue=2;
I have a textbox named textbox1 and a dropdownlist. Dropdownlist contains the list of branches and i want that when i select a branch from dropdown i want to get the respective branch code to be generated in a textbox from the Database or from c# coding. How will it be possible ?
Am I missing something, is it more complex that just putting an event handler on the dropdown so that when it's value changes it calls your method that can do whatever it needs to do to generate the string for the textbox?
Skipping passed the "database" portion of your question (and assuming your data isn't bound to the DropDownList)..
One way in ASP.NET, to accomplish this, I believe, is to have your code print DropDownList.SelectedValue's value in the textbox during an event.
Here is a link showing how to bind an event to DropDownList in jQuery
I have two Comboboxes where the second one is dependent upon the first one.
When the SelectedIndexChanged event of the first Combobox fires then the second Combobox will be enabled.
After the event, the second Combobox is enabled but I cannot select the ComboBox item.
EDIT
I use Dev express Tools
First Combo I load in Page_Load Event
I use Server Side code:
protected void ASPxComboModule_SelectedIndexChanged(object sender, EventArgs e)
{
LoadSecondCombo();
LoadSecondCombo.Focus();
}
There is no problem in loading, but I'm unable to select 2nd combo item.
What do this do: LoadSecondCombo(); I assume it returns an instance of the control. Where does it set combo.Enabled at?
LoadSecondCombo(); LoadSecondCombo.Focus();
look like method that reference your comboBox and Load it.
When you want to focus LoadSecondCombo should ne an instance of Combo Box. I think it is not and so your combo is not selected.
Can you try going back a bit and look at the Id of combo Box (if it in a composit control like DataGrid / View you will have to do a FindControl) and then focus. I mean typing
comboBtn1.Focus();
Now if that works then you know that your control can be found. In that case mofidify the LoadSescondCombo() to return an instance of combo button if it is not doing so already.
then create a reference to that combobutton by
ComboButton cbtn = LoadSecondCombo(); and
cbtn.Focus();
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