首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView在编辑状态下每行某一列不出现编辑状态(该列在RowDataBound事件里有修改悔)

2013-12-13 
GridView在编辑状态下每行某一列不出现编辑状态(该列在RowDataBound事件里有修改过)这是前台代码asp:Grid

GridView在编辑状态下每行某一列不出现编辑状态(该列在RowDataBound事件里有修改过)
GridView在编辑状态下每行某一列不出现编辑状态(该列在RowDataBound事件里有修改悔)


这是前台代码

<asp:GridView ID="gv_fm" runat="server" CellPadding="10" ForeColor="#333333" 
            GridLines="None" onpageindexchanging="gv_fm_PageIndexChanging" 
             AllowPaging="True" PageSize="16" 
            AutoGenerateColumns="False" CellSpacing="1" DataKeyNames="FM_ID" 
            HorizontalAlign="Center" onrowdatabound="gv_fm_RowDataBound" 
            onrowediting="gv_fm_RowEditing" 
            onrowcancelingedit="gv_fm_RowCancelingEdit" onrowdeleting="gv_fm_RowDeleting" 
            onrowupdating="gv_fm_RowUpdating">
            <PagerSettings FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" 
                        PreviousPageText="上一页" />
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:BoundField DataField="FM_ID" HeaderText="ID" />
                <asp:BoundField DataField="FM_Grade" HeaderText="机房模式">
                    <ItemStyle HorizontalAlign="Center" />
                    
                </asp:BoundField>
                <asp:BoundField DataField="FM_LogicID" HeaderText="逻辑码">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_WorkingModel" HeaderText="工作模式">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_FROutFreq" HeaderText="FM输出频率">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_FMOutState" HeaderText="FM输出状态">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_Acoutstate" HeaderText="受控电源输出状态">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_Model" HeaderText="型号">
                    <ItemStyle HorizontalAlign="Center" Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_PhysicalAddress" HeaderText="物理地址">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_Group" HeaderText="所在组号">


                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_Remark" HeaderText="备注">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="FM_Time" HeaderText="时间">
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:CommandField HeaderText="编辑" ShowEditButton="True" >
                    <ItemStyle Width="120px" />
                </asp:CommandField>
                <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
[解决办法]
我看你那个是不是将

    <asp:BoundField DataField="FM_Grade" HeaderText="机房模式">
                    <ItemStyle HorizontalAlign="Center" />
                    
                </asp:BoundField> 
  
换成:
  
<asp:TemplateField HeaderText="机房模式">
                <ItemTemplate>
                    <%# Eval("FM_Grade")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:HiddenField ID="HDF_Grade" runat="server" Value='<%# Eval("FM_Grade") %>' />
                    <asp:DropDownList ID="DDL_Grade" runat="server" Width="90px" />
                </EditItemTemplate>
                <ItemStyle Width="100px" />
            </asp:TemplateField>
 
后台RowDataBound中:


if (((DropDownList)e.Row.FindControl("DDL_Grade")) != null)
        {
            DropDownList ddlSex = (DropDownList)e.Row.FindControl("DDL_Grade");
            ddlSex.Items.Clear();
            ddlSex.Items.Add(new ListItem("市级", "市级"));
            ddlSex.Items.Add(new ListItem("县级", "县级"));
            ddlSex.Items.Add(new ListItem("镇级", "镇级"));
            ddlSex.Items.Add(new ListItem("村级", "村级"));
        
            //ddlSex.Items.Add(new ListItem("男"));
            //ddlSex.Items.Add(new ListItem("女"));
            //DropDownList初始被选择的项
            ddlSex.SelectedValue = ((HiddenField)e.Row.FindControl("HDF_Grade")).Value;
        }




你的ID列 就直接可以隐藏了  不要显示出来  


[解决办法]
<asp:BoundField DataField="FM_WorkingModel" ReadOnly="True"
对于<asp:TemplateField
只写<ItemTemplate> 去掉<EditItemTemplate>

热点排行