Reputation: 22323
public static List<TemplateInfo> GetTemplateList()
{
DirectoryInfo dir = new DirectoryInfo("E://DotNetProjects//sftemplating//Templates");
List<TemplateInfo> lstTemplates = new List<TemplateInfo>();
foreach (DirectoryInfo temp in dir.GetDirectories())
{
TemplateInfo tempObj = new TemplateInfo(temp.Name);
lstTemplates.Add(tempObj);
}
return lstTemplates;
}
and
public void BindTemplate()
{
ddlTemplateList.DataSource = GetTemplateList();
ddlTemplateList.DataBind();
}
info is
public class TemplateInfo
{
public string TemplateName { get; set; }
public TemplateInfo() { }
public TemplateInfo(string TemplateName)
{
this.TemplateName = TemplateName;
}
}
and i call BindTemplate in pageload like this
if (!IsPostBack)
{
BindTemplate();
}
but ddlTemplateList
is bind with Templating.TemplateInfo
.Templating is my namespace.Whats my problem.Plz help to find my mistake.
Upvotes: 0
Views: 44
Reputation: 176946
I think you miss to assgin thie
ddlTemplateList.DataTextField="texttodisplay" ;
ddlTemplateList.DataValueField="value";
You your code will be
public void BindTemplate()
{
ddlTemplateList.DataSource = GetTemplateList();
ddlTemplateList.DataTextField="texttodisplay" ;
ddlTemplateList.DataValueField="value";
ddlTemplateList.DataBind();
}
Upvotes: 1