views:

51

answers:

2

I did drop down list that fill its value from database But when it run it dose not get first row and get others and if I add new it get it what is the problem?

private void LoadWithCategory()
{
    if (Request.QueryString["Category_Id"] != null)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {
            SqlCommand Com = new SqlCommand("GetProducFamilyTP", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(
                Parameter.NewInt("@Category_Id", Request.QueryString["Category_Id"]));
            SqlDataReader DR = Com.ExecuteReader();

            if (DR.Read())
            {
                DDLProductFamily.DataSource = DR;
                DDLProductFamily.DataTextField = "Name";
                DDLProductFamily.DataValueField = "ProductCategory_Id";
                DDLProductFamily.DataBind();
            }
            else
            {
                DDLProductFamily.Visible = false;
            }
        }
    }
}
A: 

Please show us your code. How are you adding items to the DropDown list? Remember, collections etc. first item is at index 0, not 1. I would bet money that you are adding items starting with DropDownList.Add.Item(YourItem[1]) instead of YourItem[0].

TheGeekYouNeed
protected void DDLProductFamily_DataBound(object sender, EventArgs e) { DDLProductFamily.Items.Insert(0, new ListItem("Filter With ProductCategory", "0")); }
KareemSaad
A: 

Try this and check if your code works or not

     protected void DPBind(ArrayList list)
     {
          list.Insert(0, "your First Item");
          dropdownlist1.datasource = list;
          dropdownlist1.dataBind();
     }
Nasser Hadjloo
i Did that protected void DDLProductFamily_DataBound(object sender, EventArgs e) { DDLProductFamily.Items.Insert(0, new ListItem("Filter With ProductCategory", "0")); }
KareemSaad
So whats the problem with you ?
Nasser Hadjloo