c# - Binding Data text field, Data value field to asp:Dropdownlist -
I created an assistant function to bind the drop down list in asp.net. View my function:
Public Zero BindDDL (String Query, Dropdown List DDL) {List & lt; Issuetype & gt; Obj = new list & lt; Issuetype & gt; (); Issuetype iss = new Issuetype (); Iss.DeptId = 1; Iss.Issue = "SSS"; Iss.IssuetypeId = 4; Obj.Add (ISS); // Balisu BL = New Balance (); // from the list & lt; Issuetype & gt; 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, the drop-down should be bound by the list of the insuity unit, you can see the properties of Issuetype in the code.
But although I am not able to set DataValueField and DataTextField correctly. Every time this index is saying outside the category.
data value field and datattextfield Should be the name of the field, not the value from the collection.
DDL.DataSource = obj; DDL.DataValueField = "Problem"; // Example Choose what is needed DDL.DataTextField = "IssuetypeId"; // Choose the example, what is required DDL Databund (); The exception has been thrown because you have 1 item in your archive, but you try to keep the second item (not present) in DataTextField . But if you fix your code then it is not relevant.
Comments
Post a Comment