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>

New Topic/Question
Reply




MultiQuote





|