Hi ,
I have a gridview ..In Gridview 4 Dropdown and 3 Labels. i want to fill Sql Server Database value in these dropdowns and labels.
Now the problem is that Only in one Label [unit fill from the database] . other two labels not fill.
- protected void Gridview3_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- SqlCommand cmd = new SqlCommand("Select ValueId,Value1,Unit2,Unit1,Unit21,Value2,Value21,Discription from tblMatValueTemp1 where ItemId = '" + lblItem.Text + "' ", myconn);
- cmd.CommandType = CommandType.Text;
- SqlDataAdapter da = new SqlDataAdapter();
- da.SelectCommand = cmd;
- DataTable dt = new DataTable();
- DataSet ds = new DataSet();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("ddlValue1");
- DropDownList DropDownList2 = (DropDownList)e.Row.FindControl("ddlValue2");
- DropDownList DropDownList3 = (DropDownList)e.Row.FindControl("ddlDisp");
- DropDownList DropDownList4 = (DropDownList)e.Row.FindControl("ddlValue21");
- Label lbl1 = (Label)e.Row.FindControl("lblSValues");
- Label lbl2 = (Label)e.Row.FindControl("lblcr1");
- Label lbl3 = (Label)e.Row.FindControl("lblcr2");
- DropDownList1.DataSource = dt;
- DropDownList1.DataTextField = "Value1";
- DropDownList1.DataValueField = "Value1";
- DropDownList1.DataBind();
- lbl1.Text = dt.Rows[0]["Unit1"].ToString(); --------Label 1
- DropDownList2.DataSource = dt;
- DropDownList2.DataTextField = "Value2";
- DropDownList2.DataValueField = "Value2";
- DropDownList2.DataBind();
- DropDownList4.DataSource = dt;
- DropDownList4.DataTextField = "Value21";
- DropDownList4.DataValueField = "Value21";
- DropDownList4.DataBind();
- lbl2.Text = dt.Rows[0]["Unit2"].ToString();--------Label 2 [This label is blank no value fill]
- lbl3.Text = dt.Rows[0]["Unit21"].ToString();--------Label 3 [This label is blank no value fill]
- DropDownList3.DataSource = dt;
- DropDownList3.DataTextField = "Discription";
- DropDownList3.DataValueField = "Discription";
- DropDownList3.DataBind();
- }
- }
- }