Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET DropDownList
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 20-Jan-13 0:31am

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.

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

 
Try the above code...
  Permalink  
Comments
Nasser Abu Farah at 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 at 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
0 OriginalGriff 515
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 209
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
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