Hi nauna,
Refer below sample. In the example i am binding the DropDownList from Default page. You can bind it in UserControl as well.
HTML
UserControl
<asp:DropDownList ID="ddlFruits" runat="server" Width="60%">
</asp:DropDownList>
Default
<%@ Register Src="~/WebUserControl.ascx" TagName="Fruits" TagPrefix="uc" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc:Fruits ID="ucFruits" runat="server" />
</form>
</body>
</html>
Code
Default
C#
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl ctrl = (WebUserControl)Page.FindControl("ucFruits");
DropDownList ddlFruits = ctrl.FindControl("ddlFruits") as DropDownList;
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id"), new System.Data.DataColumn("Name") });
dt.Rows.Add(1, "Apple");
dt.Rows.Add(2, "Orange");
dt.Rows.Add(3, "Banana");
dt.Rows.Add(4, "Grapes");
ddlFruits.DataSource = dt;
ddlFruits.DataTextField = "Name";
ddlFruits.DataValueField = "Id";
ddlFruits.DataBind();
ddlFruits.Items.Insert(0, new ListItem("Please Select Fruit", "0"));
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ctrl As WebUserControl = CType(Page.FindControl("ucFruits"), WebUserControl)
Dim ddlFruits As DropDownList = TryCast(ctrl.FindControl("ddlFruits"), DropDownList)
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.AddRange(New Data.DataColumn() {New Data.DataColumn("Id"), New Data.DataColumn("Name")})
dt.Rows.Add(1, "Apple")
dt.Rows.Add(2, "Orange")
dt.Rows.Add(3, "Banana")
dt.Rows.Add(4, "Grapes")
ddlFruits.DataSource = dt
ddlFruits.DataTextField = "Name"
ddlFruits.DataValueField = "Id"
ddlFruits.DataBind()
ddlFruits.Items.Insert(0, New ListItem("Please Select Fruit", "0"))
End Sub
Screenshot