I have entered data into textbox and stored in sql server in the page1. Now i want to retrieve that entered data into dropdown list and also when that category appears in dropdownlist , i have a textbox where i can select a category from dropdownlist and enter the data related to that category in page 2.. In page 3 , i want a gridview to display the contents in the dropdown list ....
please help me out. i am new into .net
Thanks and regards
Antony
Loading
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 3:36 AM EDT
Consider forming the question properly so that we better understand your requirements. Please remember that we cannot read your mind/HardDisk. Please explain a little more.
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 3, 2013, 3:59 AM EDT
for page 2..
add namespace---
using System.Data;
using System.Data.SqlClient;
add this code to yout page_load event after put your real data(database name,tablename,fieldname etc..)
SqlConnection conn = new SqlConnection(@"server=servername;User Id=sa;Password=yourpassword;Initial Catalog=databasename");
SqlCommand cmd = new SqlCommand("select yourcolumn from your table1", conn);
cmd.CommandTimeout = 0;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "column name";
DropDownList1.DataValueField = "column name";
DropDownList1.DataBind();
after that on your button click event write this code..to save data...
SqlConnection conn = new SqlConnection(@"server=servername;User Id=sa;Password=yourpassword;Initial Catalog=databasename");
SqlCommand cmd = new SqlCommand("insert into table2 (ddlfield,ttextfield) values("+DropDownList1.SelectedItem.Text+","+TextBox1.Text+")", conn);
cmd.CommandTimeout = 0;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
if i am going in right direction then do it and then tell me..i'll give code for page 3.
antony victor90 reputationPosted Jun 3, 2013, 4:17 AM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 3, 2013, 5:05 AM EDT
On third page pic a ddl with autopostback true property.
on page load...
write this code..
on ddl selectedindexchanged event write this code
mark as answered if its helpful.
thanks
antony victor90 reputationPosted Jun 5, 2013, 12:29 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts