an empty textbox in datagrid [Resolved]

Posted by Sashi under ASP.NET on 2/15/2016 | Points: 10 | Views : 164 | Status : [Member] | Replies : 2
how to code for an empty textbox in data grid. that textbox should not take any value yet it should be visible . how this can be designed using .net c#




Responses

Posted by: Rajnilari2015 on: 2/15/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Sashi Sir,
Make ReadOnly="true" in your textbox. e.g.

e.g.

<asp:TemplateField HeaderText="My Readonly Textbox">
<ItemTemplate>
<asp:TextBox ID="txtReadOnly" runat="Server" ReadOnly="true"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

Suppose if we have controls in each row of gridview, then we need to first find out the controls for each row and then to set the "readonly" property.This we need to do at the RowDataBound event of the datagrid. An example will make things clear for you

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var txt = (TextBox)e.Row.FindControl("txtReadOnly");
if(txt !=null)
{
txt.Attributes.Add("readonly", "readonly");
}
}
}


Hope this helps.

--
Thanks & Regards,
RNA Team

Sashi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/16/2016 [Member] Bronze | Points: 25

Up
0
Down
Have you done with bind and Eval in GridView.. Eval also work, if we dont want to update in GridView.

Feel free to share informations 9731764134
Thanks

Sashi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response