editing a cell in an asp:datagrid
I have a asp:DataGrid which holds data in two colu开发者_如何学Gomns 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?
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" />
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>
精彩评论