4b0
4b0

Reputation: 22323

should not able to bind list in asp.net

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

Answers (1)

Pranay Rana
Pranay Rana

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

Related Questions