문제

VS2010 .net

I have a gridview that displays information from a database. One of the fields is a checkbox. What I would like to do is be able to click the checkbox and have it update back to the database, but the checkbox field is grayed-out. Below is my markup. searching for making checkboxes clickable does not return any helpful results.

<asp:GridView ID="gvSiteInfo" runat="server" BackColor="White" 
    GridLines="Vertical" AutoGenerateColumns="False" OnSorting="gvSiteInfo_Sorting" 
    onselectedindexchanged="gvSiteInfo_SelectedIndexChanged" 
    AllowSorting="True">
    <Columns>
        <asp:BoundField DataField="prodServer" HeaderText="Production Server" 
            SortExpression="prodServer" />
        <asp:BoundField DataField="prodHostHeader" HeaderText="Production Host Header" 
            SortExpression="prodHostHeader" />
        <asp:BoundField DataField="prodIP" HeaderText="Production IP Address" 
            SortExpression="prodIP" />
        <asp:CheckBoxField DataField="testComplete" HeaderText="Testing Completed" 
            SortExpression="testComplete" />
    </Columns>
</asp:GridView>
도움이 되었습니까?

해결책

You should use a templatefield:

                       <asp:TemplateField>
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelector" runat="server"
                                    ToolTip="Select row?" />
                            </ItemTemplate>
                        </asp:TemplateField>

You also do not seem to set the value based on the database:

Checked='<%# DataBinder.Eval(Container, "DataItem.IsChecked") %>'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top