I am loading a Dropdown inside a repeater but i am unable to see the repeater.Why i am unable to see it?
aspx:
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Select</asp:ListItem> <asp:ListItem>Left</asp:ListItem>
<asp:ListItem>Right</asp:ListItem>
<asp:ListItem>SubString</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList6" runat="server"> </asp:DropDownList>
codebehind:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataTable dt = new DataTable();
dt = Common.LoadExample();
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList6") ;
ddl.DataSource = dt;
ddl.DataTextField = "Name";
ddl.DataValueField = "Name";
ddl.DataBind();
}
// datatable for loading
public static DataTable LoadExample()
{
DBAccess objDBAccess = new DBAccess();
DataTable dt = new DataTable();
try
{
objDBAccess.AddParameter("@Name", SqlDbType.VarChar);
dt = objDBAccess.ExecuteDataTable("usp_test");
return dt;
}
catch
{
return null;
}
}
I assume the reason is that you haven’t checked for the
ItemType, therefore you’re getting an exception because the header doesn’t contain theDropDownListbut only the items:Of course there are other reasons why a repeater is not visible.
Repeateror one of it’s container controls isVisible="false"DataSourceis null or emptyEdit Please don’t comment but edit your question with important informations.
Then you have not
DataBindit or theDataSourceis null or empty. You should show us the code where you assign the datasource and call databind.