I have created template field with a ddl. I have instantiated an SPGridview and the ddl shows up but only with the default choice values. How do I bind to the actual values of the List item record?
Here is my code:
public class ItemTemplateDDL:ITemplate
{
private string _NAME;
private string _DATAVALUEFIELD;
private string _DATATEXTFIELD;
private SPWeb _SITE;
private string _LISTNAME;
public ItemTemplateDDL(string ddlName, string DataValueField, string DataTextField, SPWeb site, string list)
{
this._DATATEXTFIELD = DataTextField;
this._DATAVALUEFIELD = DataTextField;
this._LISTNAME = list;
this._SITE = site;
this._NAME = DataTextField;
}
public void InstantiateIn(Control container)
{
DropDownList ddl = new DropDownList();
ddl.DataBinding += new EventHandler(ddl_Databinding);
ddl.SelectedIndexChanged +=new EventHandler(ddl_SelectedIndexChanged);
container.Controls.Add(ddl);
}
private void ddl_Databinding(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
SPList dataList = _SITE.Lists[_LISTNAME];
SPFieldChoice field = (SPFieldChoice)dataList.Fields[_DATAVALUEFIELD];
ddl.DataSource = field.Choices;
}
private void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string h = "";
}
}