Gridview Checkbox Not Updating

asp.net , gridview , checkbox , update United States
  • 8 years ago

    I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to add another checkbox column, the sql database isn't updated properly with a 0/1 or false/true but with null. I've tried everything I can think of. Can anyone help?

    <asp:BoundField DataField="roomID" />                       
    <asp:TemplateField HeaderText="RoomName">
    <EditItemTemplate>
    <asp:TextBox ID="txtRoom" Columns="10" runat="server" SkinID="txtSm" Text='<%# Bind("roomname") %>' />
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblRoom" runat="server" Text='<%# Bind("roomName") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Button ID="btnAdd"  runat="server" skinID="btnGo" Text="Add" CommandName="Insert" />
    <asp:TextBox ID="txtRoomAdd" Columns="10" runat="server" SkinID="txtSm" />
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Org">
    <EditItemTemplate>
    <asp:DropDownList ID="orgDDL" runat="server" SkinID="ddl" DataSourceID="orgDS"
    DataTextField="org" DataValueField="orgID" SelectedValue='<%# Bind("orgID") %>'>
    </asp:DropDownList><asp:SqlDataSource ID="orgDS" runat="server" ConnectionString="<%$ ConnectionStrings:Str  %>"
    SelectCommand="select statement"></asp:SqlDataSource>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblOrg" runat="server" Text='<%# Bind("org") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:DropDownList ID="orgDDLAdd" runat="server" SkinID="ddl" DataSourceID="orgAddDS2"
    DataTextField="org" DataValueField="orgID">
    </asp:DropDownList><asp:SqlDataSource ID="orgAddDS2" runat="server" ConnectionString="<%$ ConnectionStrings:Str  %>"
    SelectCommand="select statement">
    </asp:SqlDataSource>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Type">
    <EditItemTemplate>
    <asp:DropDownList ID="typeDDL" runat="server" SkinID="ddl" DataSourceID="typeDS"
    DataTextField="roomType" DataValueField="roomTypeID" SelectedValue='<%# Bind("roomTypeID") %>'>
    </asp:DropDownList><asp:SqlDataSource ID="typeDS" runat="server" ConnectionString="<%$ ConnectionStrings:Str  %>"
    SelectCommand="select statement">
    </asp:SqlDataSource>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblroomType" runat="server" Text='<%# Bind("roomType") %>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:DropDownList ID="typeDDLAdd" runat="server" SkinID="ddl" DataSourceID="addDS3"
    DataTextField="roomType" DataValueField="roomTypeID">
    </asp:DropDownList><asp:SqlDataSource ID="addDS3" runat="server" ConnectionString="<%$ ConnectionStrings:Str  %>"
    SelectCommand="select statement">
    </asp:SqlDataSource>
    </FooterTemplate>
    </asp:TemplateField>                                    
    <asp:TemplateField HeaderText="DialOut">
    <EditItemTemplate><asp:CheckBox ID="chkOutEdit" runat="server" checked='<%# Bind("dialOut") %>' /></EditItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="chkOut" runat="server" checked='<%# Bind("dialOut") %>' Enabled="false" /></ItemTemplate>
    <FooterTemplate><asp:CheckBox ID="chkOutAdd" runat="server" /></FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="DialIn">
    <EditItemTemplate><asp:CheckBox ID="chkInEdit" runat="server" checked='<%# Bind("dialIn") %>' /></EditItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="chkIn" runat="server" checked='<%# Bind("dialIn") %>' Enabled="false" /></ItemTemplate>
    <FooterTemplate><asp:CheckBox ID="chkInAdd" runat="server" /></FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Webinar">
    <EditItemTemplate><asp:CheckBox ID="chkWebEdit" runat="server" checked='<%# Bind("webinarCapable") %>' /></EditItemTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="chkWeb" runat="server" checked='<%# Bind("webinarCapable") %>' Enabled="false" /></ItemTemplate>
    <FooterTemplate><asp:CheckBox ID="chkWebAdd" runat="server" /></FooterTemplate>
    </asp:TemplateField>
    

    Update stuff: UpdateCommand="update myTable set roomname=@roomName,orgID=@orgID, roomTypeID=@roomTypeID,dialOut=@dialout,dialIn=@dialin,webinarCapable=@web WHERE roomID = @roomID" >

    TABLE [dbo].[myTable](
        [roomID] [int] IDENTITY(1,1) NOT NULL,
        [roomName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
        [orgID] [int] NULL,
        [roomTypeID] [int] NULL,
        [dialOut] [bit] NULL CONSTRAINT [DF_xTblRoom_dialOut]  DEFAULT ((0)),
        [dialIn] [bit] NULL CONSTRAINT [DF_xTblRoom_dialIn]  DEFAULT ((0)),
        [webinarCapable] [bit] NULL CONSTRAINT [DF_xTblRoom_webinarCapable]  DEFAULT ((0))
    
  • 8 years ago

    Not sure what I did wrong, still, but I deleted the aspx page and started over from scratch. Everything works fine now..... Scratchin' my head hard!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”