Wednesday, June 9, 2010

Load Checkbox from database asp.net 3.5 c# sql-server

Load Checkbox from database asp.net 3.5 c# sql-server

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="chkbx.aspx.cs" Inherits="chkbx" %>

<!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>
    <style type="text/css">
        .style1
        {
            width: 25%;
        }
    </style>
</head>
<body text="dssdds">
    <form id="form1" runat="server">
    <div>
   
        <table align="center" class="style1">
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataSourceID="SqlDataSource1" DataTextField="co" DataValueField="co">
                    </asp:DropDownList>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                        ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
                        SelectCommand="SELECT [co] FROM [boconn]"></asp:SqlDataSource>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox1" runat="server" Text="Media1"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox2" runat="server" Text="Media1 Date"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox3" runat="server" Text="Media3"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox4" runat="server" Text="Media3 Date"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox5" runat="server" Text="Boxes"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox61" runat="server" Text="Cryosettes"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox6" runat="server" Text="50ml Tubes"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox7" runat="server" Text="Gel Packs"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox8" runat="server" Text="Media Labels"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox9" runat="server" Text="Procurment Forms"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox10" runat="server" Text="Consent Forms"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox11" runat="server" Text="Last LN2 fill"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox12" runat="server" Text="Next LN2 fill"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:CheckBox ID="CheckBox13" runat="server" Text="Fedex Forms"  />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class chkbx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         CheckBox1.Checked =false;
         CheckBox2.Checked = false;
         CheckBox3.Checked = false;
         CheckBox4.Checked = false;
         CheckBox5.Checked = false;
         CheckBox6.Checked = false;
         CheckBox61.Checked = false;
         CheckBox7.Checked = false;
         CheckBox8.Checked = false;
         CheckBox9.Checked = false;
         CheckBox10.Checked = false;
         CheckBox11.Checked = false;
         CheckBox12.Checked = false;
         CheckBox13.Checked = false;
//Load Data
        loadchkdata();
    }

    void loadchkdata()
    {
        string strSQL;
        SqlConnection myConnection = new SqlConnection(ConnectionString);
        strSQL = "select * FROM BOVBFL WHERE VBFLT='" + DropDownList1.SelectedItem.Text +"'";
        SqlCommand cmd = new SqlCommand(strSQL, myConnection);
        myConnection.Open();
        SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        while (myReader.Read())
        {
            if (myReader["VBROWS"].ToString() == "media1tr")
            {
                CheckBox1.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "media1datetr")
            {
                CheckBox2.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Media3")
            {
                CheckBox3.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "media3datetr")
            {
                CheckBox4.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Boxestr")
            {
                CheckBox5.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Cryosettes")
            {
                CheckBox61.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "qutytr")
            {
                CheckBox6.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "GelPackstr")
            {
                CheckBox7.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "mediaTr")
            {
                CheckBox8.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Procurmenttr")
            {
                CheckBox9.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Consenttr")
            {
                CheckBox10.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "Fedextr")
            {
                CheckBox13.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "lnfilltr")
            {
                CheckBox11.Checked = true;
            }
            if (myReader["VBROWS"].ToString() == "shipfozenstr")
            {
                CheckBox12.Checked = true;
            }
  
        }

        myReader.Close();
        myConnection.Close();
    }

    private string ConnectionString
    {
        get
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
            return connectionString;
        }
    }

}

No comments: