Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
C#
string con_str = @"Data Source=DATABASE;Initial Catalog=abc;Integrated Security=True";
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DropDownList1.Items.Clear();
                DropDownList1.Items.Add("");
                SqlConnection con = new SqlConnection(con_str );
                con.Open();

                string es = "select year from table1";
                SqlCommand ees = new SqlCommand(es, con);
                SqlDataReader rdr = ees.ExecuteReader();

                while (rdr.Read())
                {
                    DropDownList1.Items.Add(rdr.GetString(0));

                }
      
                DropDownList1.DataBind();
    }

        }

now i want to add this dropdown value to another table in a new column

for example

dropdownselected--(2011)

sql roll name year(new column added)
1 222 abx 2011
2 333 eeqa 2011
3 342 bdh 2011


i will select 2011 and this will populate in the table in all the rows
Posted
Updated 7-Aug-14 1:12am
v4
Comments
Karthik Harve 7-Aug-14 7:21am    
Have you tried using "Selected Index Changed" event of dropdown list ? On this event just update the database table. have you tried this ?
10923679 7-Aug-14 7:22am    
no i havent tired that..
i dont have much ide abt Asp.net.

can u have with Selected Index Changed ?


Thanks7872 7-Aug-14 8:01am    
If you don't have much idea about asp.net than you won't be able to understand the solution provided by members here. Its just waste of time for you and for all.
10923679 8-Aug-14 0:35am    
but.. members are helping me a lot... and m learning here.
anyway thank your time .
10923679 7-Aug-14 7:24am    
Actually i want to fill the new column of the table by dropbox value=2000 or 2001 to all rows which existing table.

Hi

about selected index changed event refer MSDN article:
MSDN-ListControl Selected Index Changed Event[^]

In that event, just update the database table using below sql query by passing the selected value of the dropdown list

SQL
Declare @year int
set @year = @dropdownvalue --pass your dropdown value here
update table1 set year=@year
GO


hope this helps.
 
Share this answer
 
UPDATE table SET new column = '@year from Dropdown' where column like '%'

this will update all the rows of the recorded table..
 
Share this answer
 

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