Reputation: 263
I have a grid and I need to get readonly textbox value in gridview c# from code behind
Upvotes: 2
Views: 652
Reputation: 11
protected void grd1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (txt.Text != "")
{
txt.Attributes.Add("readonly", "readonly");
txt.Visible = false;
lbltaskname.Visible = true;
}
else
{
txt.Attributes.Remove("readonly");
}
}
}
Upvotes: 1
Reputation: 1
You can do itself on aspx page.
Assuming that dataset is attached(bind) to the grid from code behind, now coming to gridview on aspx page , add textbox control to grid , in text property of texbox assign value from dataset by -
<%# Bind("your_column_name")%>
and add
readonly = true
to textbox.
Thanks
Upvotes: 0