Dropdownlist data not insert in query in asp.net page - c#

I placed five dropdownlists and three textboxes in asp.net webpage. The value select in dropdownlist and insert in textboxes are the values to be insert in query for where condition. Now the problem is that when I press search button for execution the values from text boxes are inserted in query but the dropdownlist values remain empty, and the result is not showing. I check code for dropdownlist like:
ddlChannel.SelectedValue;
ddlChannel.Text;
ddlChannel.SelectedItem;
but not any selected value is inserted from the query. Either problem in on pageLoad. I use Page_Prerender method to load dropdownlist from database through query execution. Any idea what the problem might be?

the selected values from your dropdownlists are most likely reset on postback ( when you click search button )
you can use the following code to avoid resetting your dropdownlists
if(!Page.IsPostBack)
{
//Bind dropdown lists logic
}

you have to set controls autopostback property true, eventvalidation set false on page pl

Related

FormView row count

I have created an application which uses a FormView with Select and Update commands, the formview will only populate when I pass it a parameter, however here is where the problem is. If I pass the formview a parameter but in my database there is more than 1 row I want to be able to choose which row populates the formview using something like a dropdownlist as a formview only holds 1 row.
Since there's no code, I'll answer with words as well:
Click on FormView control
Go to properties and set AllowPaging to true // Adding this property generates the paging interface automatically, which will display numbers for each record return from your database

Textarea in gridview showing old values before saving and binding

I have a GridView which consists of Textbox in each row and its textmode property is set to 'Multiline'.
Whenever I edit the Textbox and click Save button, the edited Textbox in gridview shows the old values for a second, gets saved in database and binds the new value.
The GridView is enclosed in an UpdatePanel and also its ViewState property is set to false.
Binding is done only after saving the records.
I don't know where it is going wrong.
I have a feeling it has something to do with when your databinding.
Try setting the viewstate back to true, then databind your gridview on
1) !Page.IsPostback
2) After you have finished the save operation

Is partial page reload possible in asp.net?

I got 2 .aspx pages ,
page one(1) to insert data .....
page two(2) to view data using a gridview.
There's an edit button in the gridview , it will redirect the to page(1) and load the specific values to the textboxes, dropdowns according to the selected record.
Session is used to carry out the record from page(1) to page(2).
In the page load of page(1), if Session is not NULL it will load the values to the textboxes and etc.
My problem is , I have enabled Autopostback=true in one of the dropdowns,(to enable few more textbox's to appear when specific options are selected).
So when those options are selected page will be reloaded,when reloading it will load the specific values to the textboxes .... as the Session is not null. And the purpose of dropdown is not fulfilled because it keeps loading values to the textboxes , but not enabling the textboxes which i need to appear + the value of the selected dropdown doesnt get changed to the selected value as it loads values from the database to the dropdown too.
Any solutions ?
I sounds like you're looking for a partial postback solution.
The UpdatePanel should solve this for you:
http://www.encodedna.com/2013/02/aspdotnet.postback-updatepanel.htm

dropdownlist selectedvalue

I've used a webservice to create a dropdownlist of countries and I'm trying to add the dropdownlist selection to the sql database, but when I do that by using ddlCountry.SelectedValue in my insert statement, only the first value in the dropdownlist is showing up in the table. Should I use onselectedindexchanged to somehow store the value? What code should I be using?
Try using ddlCountry.SelectedItem.Value instead.
You need to make sure you're not repopulating your dropdown from the web service on a postback. That will cancel out your selection.
If you are firing some sort of save function on button click's even then you can go ahead with ddl.SelectedItem.Text (if you wan't to store the text in your table) if you want to store the value part of the country list then go ahead with ddl.SelectedItem.Value
SelectedIndexChanged should be only used if you want to perform some action at the time when user selects an item in the drop down

Dropdown list selected item always set to default value

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

Categories

Resources