1 Replies - 1853 Views - Last Post: 08 November 2012 - 06:21 PM Rate Topic: -----

#1 satyamisno1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-November 12

why checkboxes are not comming in output?

Posted 08 November 2012 - 03:41 AM

I Created a code for displaying checkboxes dynamically from SQL Server data.
and a button bellow to pass the checked values to second page in ASP.NET for jquery mobile site.
but iam not getting checkboxlist there.. why??

WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace myApp
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        //CheckBoxList PersonList;
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckBoxList ArtistList;
            PersonList = new CheckBoxList();
            PersonList.AutoPostBack = true;
            //ArtistList.SelectedIndexChanged = new EventHandler(ArtistList.SelectedIndexChanged);
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select Name from Person_Details", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                PersonList.Items.Add(dr[0].ToString());
            }
            dr.Close();
            con.Close();
            Page.Form.Controls.Add(PersonList);
            Session["PersonListviewstate"] = PersonList;
        }
        protected void PersonList_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString);
            SqlCommand cmd1 = new SqlCommand("select count(*) from Person_Details", con);
            con.Open();
            SqlDataAdapter SDA1 = new SqlDataAdapter(cmd1);
            DataSet ds1 = new DataSet();
            int num = SDA1.Fill(ds1);
            //int num= Sql(select count(*) from Person_Details);
            for (int i = 0; i < num; i++)
            {
                string name = PersonList.SelectedItem.ToString();
                SqlCommand cmd = new SqlCommand("select * from Person_Details where Name='" + name + "'", con);
                //con.Open();
                SqlDataAdapter SDA = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                SDA.Fill(ds);
                Session["dsPersonDetails"] = ds;
            }
            Response.Redirect("WebForm2.aspx");
        }
    }

}


WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="myApp.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=0" />
    <link rel="stylesheet" href="stylesheets/jquery.mobile-1.1.1.min.css" />
    <link rel="stylesheet" href="stylesheets/CssForMobileApp.css" />
    <style type="text/css" title="currentStyle">
        @import "stylesheets/media/css/demo_page.css";
        @import "stylesheets/media/css/header.ccss";
        @import "stylesheets/media/css/demo_table.css";
    </style>
    <script type="text/javascript" src="libraries/jquery-1.8.2.min.js"> </script>
    <script type="text/javascript" src="libraries/jquery.dataTables.min.js"> </script>
    <script type="text/javascript" src="libraries/jquery.mobile-1.2.0.min.js"></script>
    <script type="text/javascript" src="libraries/JavascriptForMobileApp.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div data-role="page" id="CheckboxListPage">
            <div id="header" data-theme="b" data-role="header">
                <h3>
                    List of Persons
                </h3>
            </div>
            <div data-role="content" data-theme="a" data-mini="true">
                <div>	
                    <asp:CheckBoxList ID="PersonList" 
                        runat="server" 
                        AutoPostBack="True" 
                        onselectedIndexChanged="PersonList_SelectedIndexChanged" DataSourceID="SqlDataSource1">
                    </asp:CheckBoxList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:myConStr %>" 
                        SelectCommand="SELECT [name] FROM [Person_Details]">
                    </asp:SqlDataSource>
                    <br />
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                </div>
            </div>
        </div>
    </div>
    </form>
</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: why checkboxes are not comming in output?

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 445
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: why checkboxes are not comming in output?

Posted 08 November 2012 - 06:21 PM

i'm not sure I completely understand your question. Is the checkbox list not showing up on the first page or the second page? Are you getting any error messages? What is it doing compared to what you think it should be doing?

And is there a reason you're trying to load the PersonList control using a SqlDataSource and using code in your code-behind file? Not to mention it looks like you're trying to add a PersonList control to a page that already has a PersonList control.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1