Sunil Chaudhry
Sunil Chaudhry

Reputation: 263

How to get readonly textbox value in gridview c# from code behind

I have a grid and I need to get readonly textbox value in gridview c# from code behind

Upvotes: 2

Views: 652

Answers (2)

Apurva Pawar
Apurva Pawar

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

Jaipal Singh
Jaipal Singh

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

Related Questions