TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ankit gaur
1.4k
298
32.5k
Fill Database value in Label inside Gridview
Mar 7 2019 6:38 AM
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();
}
}
}
Reply
Answers (
1
)
Source code analysis
How to insertwhole data in database.