Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使单个字段在数据绑定Gridview中可编辑_C#_Asp.net_Gridview - Fatal编程技术网

C# 使单个字段在数据绑定Gridview中可编辑

C# 使单个字段在数据绑定Gridview中可编辑,c#,asp.net,gridview,C#,Asp.net,Gridview,我希望使MAC列可编辑,因为这是一个注册应用程序,这将允许用户更新他们的注册。我已经绑定了SQL数据库中的数据,这很好。我只是不知道如何让当前的MAC绑定并仍然能够编辑。任何帮助都将不胜感激,我已经在下面发布了我的asp.net(目标框架4.5)代码 <asp:GridView ID="DataDisplay" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"

我希望使MAC列可编辑,因为这是一个注册应用程序,这将允许用户更新他们的注册。我已经绑定了SQL数据库中的数据,这很好。我只是不知道如何让当前的MAC绑定并仍然能够编辑。任何帮助都将不胜感激,我已经在下面发布了我的asp.net(目标框架4.5)代码

<asp:GridView ID="DataDisplay" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF" 
        BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" Height="78px" Width="727px" ViewStateMode="Enabled"
        OnRowCancelingEdit="DataDisplay_RowCancelingEdit" OnRowDeleting="DataDisplay_RowDeleting"
        OnRowEditing="DataDisplay_RowEditing" style="margin-right: 0px">
        <Columns>
            <asp:BoundField HeaderText="Device" DataField="Device" ReadOnly="true" ItemStyle-HorizontalAlign="Center"/>
            <asp:BoundField HeaderText="MAC Address" DataField="MAC Address" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField HeaderText="Area" DataField="Area" ReadOnly="true" ItemStyle-HorizontalAlign="Center"/>
            <asp:BoundField HeaderText="Date Registered" DataField="Date Registered" ReadOnly="true" ItemStyle-HorizontalAlign="Center"/>
            <asp:CommandField ShowEditButton="true" />
            <asp:CommandField ShowDeleteButton="true" />
        </Columns>
        <AlternatingRowStyle BackColor="#F7F7F7" />
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <SortedAscendingCellStyle BackColor="#F4F4FD" />
        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
        <SortedDescendingCellStyle BackColor="#D8D8F0" />
        <SortedDescendingHeaderStyle BackColor="#3E3277" />
    </asp:GridView>

用模板字段替换“MAC地址”边界字段:

<asp:TemplateField HeaderText="MAC Address" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:Label ID="lblMacAddress" runat="server" Text='<%#Eval("MAC Address") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="txtMacAddress" Text='<%#Bind("[Mac Address]") %>' runat="server"></asp:TextBox>
    </EditItemTemplate>
</asp:TemplateField>

编辑:

其余字段应仅具有ItemTemplate,如下所示:

<asp:TemplateField HeaderText="Device" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:Label ID="lblDevice" runat="server" Text='<%#Eval("Device") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

顺便说一句-数据字段名称中的空格不是一个好主意