Click here to Skip to main content
12,997,042 members (129,431 online)
Rate this:
 
Please Sign up or sign in to vote.
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 19-Jan-13 23:31pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100