Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have dropdown list in grid .here my question is how to bind the database data to the dropdown list in grid i am using vb.net 2.0 so please help me.

Thanks in Advance
Seshu
Posted
Updated 29-Jun-11 4:35am
v2
Comments
Shahriar Iqbal Chowdhury/Galib 29-Jun-11 16:28pm    
Did you try anything? share the codes

Did you try googling[^] this first? Or CP Articles[^]? Is this a windows forms app? Web app? What have you tried? Why isn't it working? What errors are you getting?
 
Share this answer
 
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            obj.da = new SqlDataAdapter("select Group_ID, Group_Name from dbo.Group_Details where MobileNo='" + Session["MobNo"].ToString() + "'", obj.cn);
            ds.Reset();
            obj.da.Fill(ds);
            DropDownList groupdwn = (DropDownList)e.Row.FindControl("DropDownList2");
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                groupdwn.DataSource = ds;
                groupdwn.DataValueField = "Group_ID";
                groupdwn.DataTextField = "Group_Name";
                groupdwn.DataBind();
                groupdwn.Items.Insert(0, new ListItem("Select", "0"));
            }
            else
            {
                groupdwn.DataSource = null;
                groupdwn.DataBind();
                groupdwn.Items.Insert(0, new ListItem("Select", "0"));

            }
        }
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900