View Single Post
  #2 (permalink)  
Old May 28th, 2007, 07:08 AM
sandip.mis sandip.mis is offline
Registered User
 
Join Date: Apr 2007
Location: Ahmedabad, Gujarat, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sandip.mis Send a message via Yahoo to sandip.mis
Default

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