[英]Gridview disable edit on 1 column asp.net
我正在使用gridview編輯來編輯我在gridview中的值,當我按下編輯時,所有列都可以編輯,我希望不允許編輯其中一列。
有什么方法可以做到這一點嗎?
這是我的aspx代碼:
<asp:GridView
ID="GridView1"
runat="server"
AllowSorting="True"
OnRowCommand="GridView1_SelectedIndexChanged1"
AutoGenerateEditButton="True"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
CellSpacing="10"
OnRowUpdating="GridView1_RowUpdating" ShowFooter="True"
onselectedindexchanged="GridView1_SelectedIndexChanged"
OnRowEditing="GridView1_RowEditing">
</asp:GridView>
謝謝
如果您使用的是asp:BoundField
,請嘗試
<asp:BoundField DataField="CustomerID"
ReadOnly="true"
HeaderText="Customer ID"/>
或者,如果你使用asp:TemplateField
,你也可以
EditItemTemplate
的asp:Label
渲染它 EditItemTemplate
當然,請使用EditItemTemplate。 在以下示例中,不會在編輯模式下編輯字段ID:
<asp:GridView runat="server">
<Columns>
...
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<%# Eval("ID") %>
</EditItemTemplate>
</asp:TemplateField>
...
</Columns>
</asp:GridView>
請顯示一些標記。 快速和臟我認為取決於你的標記aspx你可以從EditItem模板中刪除你要阻止編輯的列的文本框...當然還有其他解決方案:)
如果您使用的是模板字段
((TemplateField)gvGridView.Columns[index]).EditItemTemplate = null;
如果是領域
((BoundField)gvGridView.Columns[index]).ReadOnly = true;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.