I have a asp:DataGrid which holds data in two columns on my webpage. The user can select a row for editing which I do by setting the value of “EditItemIndex” and rebinding the grid. What I would like to do now is restrict the editing to just one of the cells in the row rather than both. Is this possible?
A:
You can set the "ReadOnly" attribute of the column that you don't want to edit, to true.
<asp:BoundColumn HeaderText="UserName" DataField="UserName" ReadOnly="true" />
Ed B
2010-05-18 16:33:19
A:
You could convert the BoundColumn into a TemplateField and change the text box to readonly or replace the text box with a label in the EditItemTemplate. A template field will give you a little more flexibility.
<asp:GridView ID="gridView1" runat="server">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="Label1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Germ
2010-05-18 16:34:30