Last post Aug 07, 2019 05:34 AM by Yang Shen
Member
118 Points
282 Posts
Aug 07, 2019 04:53 AM|akhterr|LINK
i want to insert data datatextfield and datavaluefield from dropdownlist to gridview....
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5PJ76B9;Integrated Security=SSPI;Initial Catalog=SPS;MultipleActiveResultSets=True;"); DataTable dt = new DataTable(); DataRow dr; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { dt.Columns.Add("Codeitem"); // dt.Columns.Add("Descriptionitem"); dt.Columns.Add("QTY"); ViewState["dt"] = dt; itemload(); } } private void itemload() { con.Open(); SqlDataAdapter adpr1 = new SqlDataAdapter("select * from ItemMasterFile ", con); DataSet dspr1 = new DataSet(); adpr1.Fill(dspr1); DropDownList1.DataSource = dspr1.Tables[0]; DropDownList1.DataTextField = "Descriptionitem"; DropDownList1.DataValueField = "Codeitem"; DropDownList1.DataBind(); } protected void GVadd_Click(object sender, EventArgs e) { dt = ViewState["dt"] as DataTable; dr = dt.NewRow(); dr["Codeitem"] = DropDownList1.SelectedValue; // dr["Descriptionitem"] = DropDownList1.SelectedItem.Text.Trim(); dr["QTY"] = txtqty.Text; dt.Rows.Add(dr); GridView1.DataSource = dt; GridView1.DataBind(); clear(); } private void clear() { // Codeitem.Text = ""; txtqty.Text = ""; } } }
Please guide....
Contributor
3140 Points
983 Posts
Aug 07, 2019 05:34 AM|Yang Shen|LINK
Hi akhterr,
It seems you have posted twice for this subject, and have marked an answer:https://forums.asp.net/t/2158515.aspx.
I have tested your current behind code along with the front code you provided earlier in above thread. After i removed the comments in your code, everything worked well.
Is there a new problem you are facing with? Please tell.
Best Regard,
Yang Shen
Member
118 Points
282 Posts
How to add datatextfield and datavaluefield from dropdownlist to gridview?
Aug 07, 2019 04:53 AM|akhterr|LINK
i want to insert data datatextfield and datavaluefield from dropdownlist to gridview....
Please guide....
Contributor
3140 Points
983 Posts
Re: How to add datatextfield and datavaluefield from dropdownlist to gridview?
Aug 07, 2019 05:34 AM|Yang Shen|LINK
Hi akhterr,
It seems you have posted twice for this subject, and have marked an answer:https://forums.asp.net/t/2158515.aspx.
I have tested your current behind code along with the front code you provided earlier in above thread. After i removed the comments in your code, everything worked well.
Is there a new problem you are facing with? Please tell.
Best Regard,
Yang Shen