Using this event we can able to find the specific controls such as textbox, dropdown, checkbox and get values from control which is used inside gridview control.
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{ //Get data row view
DataRowView drview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find dropdown control & get values
DropDownList dpEmpdept = (DropDownList)e.Row.FindControl("DrpDwnEmpDept");
string value = dpEmpdept.SelectedItem.Value;
//Find textbox control
TextBox txtname = (TextBox)e.Row.FindControl("txtName");
string Name = txtname.Text;
//Find checkbox and checked/Unchecked based on values
CheckBox chkb = (CheckBox)e.Row.FindControl("ChckBxActive");
if (drview[5].ToString() == "True")
{
chkb.Checked = true;
}
else
{
chkb.Checked = false;
}
}
}
protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{ //Get data row view
DataRowView drview = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find dropdown control & get values
DropDownList dpEmpdept = (DropDownList)e.Row.FindControl("DrpDwnEmpDept");
string value = dpEmpdept.SelectedItem.Value;
//Find textbox control
TextBox txtname = (TextBox)e.Row.FindControl("txtName");
string Name = txtname.Text;
//Find checkbox and checked/Unchecked based on values
CheckBox chkb = (CheckBox)e.Row.FindControl("ChckBxActive");
if (drview[5].ToString() == "True")
{
chkb.Checked = true;
}
else
{
chkb.Checked = false;
}
}
}
No comments:
Post a Comment