0 Replies - 5022 Views - Last Post: 07 July 2011 - 06:32 AM Rate Topic: -----

#1 taylor.alison  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 14-October 10

Bind CheckBox to bit field in Database (AJAX)

Posted 07 July 2011 - 06:32 AM

I have a checkbox that I want to load with a check in it if the entry in my gridview has been "processed" (processed means it has been checked by the user). I'm thinking the best way to do this is to have a field for each row called processed and include a checkbox in that row. When the user checks it, I want it to store a 1 in the database. also, when it loads, I want the checkbox to load with a check or not depending on that field in the database. I'm really having a hard time figuring out how to bind these two things together...I've looked at the syntax but I can't entirely tell what is going on. I have also tried it, and it doens't seem to be storing the information - because of this, I think my OnCheckedChanged event isn't working properly or at all. Any suggestions?

CS
     protected void CheckBoxProcess_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox cb = (CheckBox)sender;
            GridViewRow gr = (GridViewRow)cb.NamingContainer;
            if (cb.Checked)
            {
                OrderBrowser.Text = "checked";
            }
            else
            {
                OrderBrowser.Text = "unchecked";
            }

        }



ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="vieworders.aspx.cs" Inherits="Cabot3.custserv.vieworders" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID = "ScriptManager" runat="server" />
    <div>
        <div>
            <asp:Label runat="server" id = "orderByLabel" Text = "Order By: " />
            
            
            <asp:DropDownList runat="server" ID="orderByList" AutoPostBack="true">
                <asp:ListItem Value="fName" Selected="True">First Name</asp:ListItem>
                <asp:ListItem Value="lName">Last Name</asp:ListItem>
                <asp:ListItem Value="state">State</asp:ListItem>
                <asp:ListItem Value="zip">Zip Code</asp:ListItem>
                <asp:ListItem Value="cwaSource">Source</asp:ListItem>
                <asp:ListItem Value="cwaJoined">Date Joined</asp:ListItem>
            </asp:DropDownList>
        </div>
        <div>
            <asp:Label runat="server" ID="searchLabel" Text="Search For: " />
            <asp:TextBox ID="searchTextBox" runat="server" Columns="30" />
            <asp:Button ID="searchButton" runat="server" Text="Search" />
        </div>
    <div>
    <asp:UpdatePanel ID = "up" runat="server">
  

        
        <ContentTemplate>
        <div style= "overflow:auto; height:150px; width:700px">
        <asp:GridView ID="DefaultGrid" runat = "server" DataKeyNames = "fName, lName, zip"
        onselectedindexchanged = "DefaultGrid_SelectedIndexChanged"
        autogenerateselectbutton = "true"
        selectedindex="0">
        <SelectedRowStyle BackColor="Azure"
        forecolor="Black"
        font-bold="true" />
        <Columns>
        <asp:TemplateField HeaderText="Processed">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBoxProcess" OnCheckedChanged="CheckBoxProcess_CheckedChanged"  AutoPostBack="true" runat="server" Enabled="true" />
                    </ItemTemplate>
                </asp:TemplateField>
        </Columns>
        </asp:GridView>
        </div>
        <asp:TextBox ID="OrderBrowser" columns="70" Rows="14" runat="server" Wrap="false" TextMode="MultiLine" ReadOnly = "true">
        </asp:TextBox>
        </ContentTemplate>
        </asp:UpdatePanel>



    </div>
    </form>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1