forum

Home / DeveloperSection / Forums / Binding Data text field and Data value field to asp:Dropdownlist

Binding Data text field and Data value field to asp:Dropdownlist

Anonymous User 2013 03-Nov-2014

I have created a helper function to Bind Drop down list in asp.net. See my function:

  public void BindDDL(string query, DropDownList DDL)
    {
        List<Issuetype> obj = new List<Issuetype>();
        Issuetype iss = new Issuetype();
        iss.DeptId = 1;
        iss.Issue = "SSS";
        iss.IssuetypeId = 4;
        obj.Add(iss);
        //BALissue Bl = new BALissue();
        //List<Issuetype> objSource = null;
        //objSource = Bl.Bind_issuetypes(query);
        DDL.DataSource = obj;
        DDL.DataValueField = Convert.ToString(obj[0]);
        DDL.DataTextField = Convert.ToString(obj[1]);
        DDL.DataBind();
    }

In this way if i send the query name and Dropdownlist id to the function, drop down should be binded by the List of Issuetype entity, You can see the properties of Issuetype in code.

But however i am not able to Set the DataValueField and DataTextField correctly. Every time it is saying index out of range.


Updated on 03-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By