Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have a web Form with one DropDownList which read it's data from a table.
and I have a button next to the DropDownList which run's an insert query to add a new item to the table.
Until now every thing is fine, but what I need now is to refresh the DropDownList and automatically select the new inserted item.

Hope to solve this problem
Thank you
Posted

1 solution

Before insert the data to the database table, store the value in some variable


for ex.
<br />
Dim strNewValue$="New Data"<br />
<br />
InsertDatabase("New Data")  'Ur functionality to insert in database<br />
<br />
Dim dt as datatable = drpYourdropdown.datasource<br />
Dim dr as datarow<br />
dr=dt.NewRow()<br />
dr.Item(0)=strNewValue<br />
dt.add(dr)<br />
drpYourDropdown.datasource=dt<br />
drpYOurDropdown.databind()<br />
<br />


Try the above code...
 
Share this answer
 
Comments
Nasser Abu Farah 20-Jan-13 6:03am    
Thank you for your response
But can you explain using C# because I am not familiar with VB coding.
Than you
Sandeep Mewara 20-Jan-13 7:24am    
Not exact but something like:
{
dynamic strNewValue = "New Data";

InsertDatabase("New Data");
//Ur functionality to insert in database

DataTable dt = drpYourdropdown.datasource;
DataRow dr = null;
dr = dt.NewRow();
dr[0] = strNewValue;
dt.Rows.Add(dr);
drpYourDropdown.datasource = dt;
drpYOurDropdown.databind();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900