2 Replies - 3716 Views - Last Post: 06 November 2012 - 06:01 AM Rate Topic: -----

#1 satyamisno1  Icon User is offline

  • New D.I.C Head

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

How to generate Dynamic Checkboxes & data tables in Jquery mobile?

Posted 06 November 2012 - 02:56 AM

i wrote code for generating dynamic checkbox list from sql server and to display table in other page dynamically..
actually i wrote this in VS2010. copied into VS2012.. now it is not working..
one morething is i did not included LINQ & jquery mobile coding in to this one.. wt i have to do to work with linq & jquery mobile in this code.. and also ple tell me idea wt shd i do to work this code in VS12.

actually this code is showing some errors also.. but i could not able to solve it..

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

<!DOCTYPE html>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

    }
</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:button ID="Button1" runat="server" text="Show" onclick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="get Details" onclick="Button2_Click" />
    </div>
    </form>
</body>
</html>



webpage1.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.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace myApp
{
    public partial class CheckBoxList : System.Web.UI.Page
    {
        CheckBoxList mycblist;
        protected void Page_Load(object sender, EventArgs e)
        {
            mycblist = new CheckBoxList();
            mycblist.AutoPostBackControl = true;
            mycblist.SelectedIndexChanged = new EventHandler(mycblist_SelectedIndexChanged);
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select Name from table_name", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                mycblist.Items.Add(dr[0].ToString());
            }
            dr.Close();
            con.Close();
            Page.Form.Controls.Add(mycblist);
            Session["mycblistviewstate"] = mycblist;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        void mycblist_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (Session["mycblistviewstate"] != null)
            //{
            //    CheckBoxList cbnames = Session["mycblistviewstate"] as CheckBoxList;
            //    Page.Form.Controls.Add(cbnames);
            string name = mycblist.SelectedItem.ToString();
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConStr"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from PersonTbl where Name='" + name + "'", con);
            con.Open();
            SqlDataAdapter dad = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            dad.Fill(ds);
            Session["dsPersonDetails"] = ds;
            Response.Redirect("WebForm2.aspx");
            //}
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (Session["mycblistviewstate"] != null)
            {
                CheckBoxList cbnames = Session["mycblistviewstate"] as CheckBoxList;
                string name = cbnames.SelectedItem.ToString();
                Response.Write(name);
            }
        }
    }
}



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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>



DisplayTables.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;


namespace myApp
{
    public partial class TableDisplay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["dsPersonDetails"] != null)
            {
                DataSet ds = Session["dsPersonDetails"] as DataSet;
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }
    }
}



web.config
<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
  <connectionStrings>
    <add name="myConStr" connectionString="Data Source=vanithaads;Initial Catalog=PersonDb; Integrated Security=True"/>
  </connectionStrings>
</configuration>



Is This A Good Question/Topic? 0
  • +

Replies To: How to generate Dynamic Checkboxes & data tables in Jquery mobile?

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: How to generate Dynamic Checkboxes & data tables in Jquery mobile?

Posted 06 November 2012 - 03:40 AM

Moved to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: How to generate Dynamic Checkboxes & data tables in Jquery mobile?

Posted 06 November 2012 - 06:01 AM

what are the errors it's showing?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1