Click here to Skip to main content
11,719,185 members (82,376 online)
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 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.
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 Sergey Alexandrovich Kryukov 1,734
1 OriginalGriff 690
2 Maciej Los 569
3 Richard MacCutchan 540
4 F-ES Sitecore 510


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2015
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