using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public String ConStr;
SqlConnection cn;
SqlCommand cm;
SqlDataAdapter da;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CatBind();
}
}
protected void CatBind()
{
ConStr = System.Configuration.ConfigurationManager.AppSetti ngs["constring"].ToString();
cn = new SqlConnection(ConStr);
cm=new SqlCommand("select * from Category",cn);
da = new SqlDataAdapter(cm);
da.Fill(ds);
DrpCat.DataValueField = "CatId";
DrpCat.DataTextField = "CatName";
DrpCat.DataSource = ds;
DrpCat.DataBind();
DrpCat.Items.Insert(0, new ListItem("---Select---", "0"));
}
protected void ProBind(string id)
{
DrpPro.Items.Clear();
ConStr = System.Configuration.ConfigurationManager.AppSetti ngs["constring"].ToString();
cn = new SqlConnection(ConStr);
cm = new SqlCommand("ProList", cn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add(new SqlParameter("@proid", SqlDbType.Int, 4, "ProId"));
cm.Parameters[0].Value = Convert.ToInt32(id);
da = new SqlDataAdapter(cm);
da.Fill(ds);
DrpPro.DataValueField = "ProId";
DrpPro.DataTextField = "ProName";
DrpPro.DataSource = ds;
DrpPro.DataBind();
DrpPro.Items.Insert(0, new ListItem("---Select---", "0"));
}
protected void DrpCat_SelectedIndexChanged(object sender, EventArgs e)
{
if (DrpCat.SelectedValue !="0")
{
ProBind(DrpCat.SelectedValue.ToString());
}
}
ProList Stored Procedure
ALTER PROCEDURE dbo.ProList
@proid int=5
AS
if @proid<>0
begin
select * from Product where CatId=@proid
end
else
begin
select * from Information
end
RETURN
Sandip
|