开发者

editing a cell in an asp:datagrid

开发者 https://www.devze.com 2022-12-31 10:11 出处:网络
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. W

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号