禁止在网格视图中编辑列. [英] disable a column from editing in grid view.
本文介绍了禁止在网格视图中编辑列.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Web表单的网格视图中显示4列.当我单击编辑"时,它进入编辑模式.但是我不需要Employee_ID列成为可编辑的.怎么设置这个.请有人解决这个...我在asp中的编码在下面给出..
i am displaying 4 columns in a grid view in my web form. when i click edit it comes in edit mode. but i dont need the Employee_ID column to become editable. how too set this. pls someone resolve this...my coding in asp is given below..
<asp:GridView ID="gridRegistrationTableDetails" runat="server"
OnRowEditing="EditRecord "
OnRowCancelEdit="CancelRecord "
OnRowUpdating="UpdateRecord"
OnRowDeleting="DeleteRecord "
onselectedindexchanged="gridRegistrationTableDetails_SelectedIndexChanged"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" GridLines="Horizontal" onrowcancelingedit="CancelRecord">
<Columns>
<asp:CommandField ShowEditButton="True" CausesValidation="False" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
推荐答案
两种方式:
1.在ASPX中,如果定义了列:
Two ways:
1. In ASPX if the columns are defined:
<asp:BoundField DataField="MyProperty" HeaderText="Int" InsertVisible="False" ReadOnly="True" />
2.在文件后面的代码中:
要使列在编辑时变为只读状态,请添加此
2. In code behind file:
To make the column readonly on editing add this
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// Find the column and set it readonly
BoundField bound = GridView1.Columns[1] as BoundField;
bound.InsertVisible = false;
bound.ReadOnly = true;
}
通常,我们定义网格的列,选项1应该很好.
Generally, we define the columns of a grid and option 1 should do just fine.
这篇关于禁止在网格视图中编辑列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文