helloaspnet
Programmer
Hi
I searched the above problem in google but couldnt correlate in my case plz help
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace product
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["sqlconnorthwind"]);
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
con.Open();
String strselectcategory="select categoryname from categories";
SqlCommand cmd=new SqlCommand(strselectcategory,con);
DropDownList1.DataSource=cmd.ExecuteReader();
DropDownList1.DataTextField="categoryname";
DropDownList1.DataBind();
con.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
con.Open();
String strddlselect="select productid, productname from products join categories on products.categoryid=categories.categoryid where categoryname=@cat";
SqlCommand cmd=new SqlCommand(strddlselect,con);
cmd.Parameters.Add("@cat",DropDownList1.SelectedItem.Text);
CheckBoxList1.DataSource=cmd.ExecuteReader();
CheckBoxList1.DataTextField="productname";
CheckBoxList1.DataValueField="productid";
CheckBoxList1.DataBind();
con.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
ArrayList prodid=new ArrayList();
//String[] prodid=new String[10];
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items.Selected)
{
prodid.Add(CheckBoxList1.Items.Value);
//Label1.Text=CheckBoxList1.Value .ToString();
}
}
DataGrid2.DataSource=prodid;
DataGrid1.DataBind();
// for(int i=0;i<prodid.Count;i++)
// {
// if(prodid.Count>0)
// {
con.Open();
String selpricename="select productname,unitprice from products where productid in(@pid)";
SqlCommand cmd=new SqlCommand(selpricename,con);
SqlParameter sqp=new SqlParameter("@pid",SqlDbType.Int);
cmd.Parameters.Add("@pid",prodid.ToArray());
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds=new DataSet();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
con.Close();
//dr.Close();
// }
//
//
//
// }
}
}
}
helloaspnet
I searched the above problem in google but couldnt correlate in my case plz help
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace product
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.CheckBoxList CheckBoxList1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["sqlconnorthwind"]);
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
con.Open();
String strselectcategory="select categoryname from categories";
SqlCommand cmd=new SqlCommand(strselectcategory,con);
DropDownList1.DataSource=cmd.ExecuteReader();
DropDownList1.DataTextField="categoryname";
DropDownList1.DataBind();
con.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
con.Open();
String strddlselect="select productid, productname from products join categories on products.categoryid=categories.categoryid where categoryname=@cat";
SqlCommand cmd=new SqlCommand(strddlselect,con);
cmd.Parameters.Add("@cat",DropDownList1.SelectedItem.Text);
CheckBoxList1.DataSource=cmd.ExecuteReader();
CheckBoxList1.DataTextField="productname";
CheckBoxList1.DataValueField="productid";
CheckBoxList1.DataBind();
con.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
ArrayList prodid=new ArrayList();
//String[] prodid=new String[10];
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items.Selected)
{
prodid.Add(CheckBoxList1.Items.Value);
//Label1.Text=CheckBoxList1.Value .ToString();
}
}
DataGrid2.DataSource=prodid;
DataGrid1.DataBind();
// for(int i=0;i<prodid.Count;i++)
// {
// if(prodid.Count>0)
// {
con.Open();
String selpricename="select productname,unitprice from products where productid in(@pid)";
SqlCommand cmd=new SqlCommand(selpricename,con);
SqlParameter sqp=new SqlParameter("@pid",SqlDbType.Int);
cmd.Parameters.Add("@pid",prodid.ToArray());
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds=new DataSet();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
con.Close();
//dr.Close();
// }
//
//
//
// }
}
}
}
helloaspnet