p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Book: Wrox's Visual C# 2005 Express Edition Starter Kit (http://p2p.wrox.com/forumdisplay.php?f=243)
-   -   Combo box dropped down don't work proper (http://p2p.wrox.com/showthread.php?t=57828)

Sneha Patel May 14th, 2007 02:05 AM

Combo box dropped down don't work proper
 
Hi,

I'm using combo box with keydown event and at any key down i'm using
combo.DroppedDown = true;
but when combo text is empty,its giving exception that "Invalid argument "0". Pls can anybody help me to find out solution.



sandip.mis May 28th, 2007 07:08 AM

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


All times are GMT -4. The time now is 02:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.