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.
Anonymous User
03-Nov-2014Actually there is no obj[1] in your code because you have only one item in the obj list, so at
this line you will get the exception
Instead you can use
And to get property names use Reflection