((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataSource = neverCallCategorys;
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataTextField = "Category";
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataValueField = "Id";
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataBind();
DATALIST里下拉框控件绑定数据源,报错。
请问怎么改?
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataTextField = "Category";
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataValueField = "Id";
((DropDownList)this.m_DlCustomerInfo.FindControl("ddlYiJi")).DataBind();
DATALIST里下拉框控件绑定数据源,报错。
请问怎么改?
{
DropDownList ddl= (DropDownList)e.Row.FindControl("DropDownList1");
}
onitemdatabound="DataList1_ItemDataBound">
<HeaderTemplate><table></HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("ID") %></td>
<td><%#Eval("Name") %></td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<HeaderTemplate></table></HeaderTemplate>
</asp:DataList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataList1.DataSource = getDataTable();
DataList1.DataBind();
}
}
public DataTable getDataTable()
{
string[] name = { "zhang", "san", "li", "si", "wang", "wu", "zhao", "liu", "huang", "qi" };
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(System.Int32));
dt.Columns.Add("Name", typeof(System.String));
for (int i = 0; i < name.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = i + 1;
row[1] = name[i];
dt.Rows.Add(row);
}
return dt;
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList dd = e.Item.FindControl("DropDownList1") as DropDownList;
dd.DataSource = getDataTable();
dd.DataTextField = "Name";
dd.DataValueField = "ID";
dd.DataBind();
}
}
public void BindDrp(DropDownList ddl)
{
string[] name = { "zhang", "san", "li", "si", "wang", "wu", "zhao", "liu", "huang", "qi" };
DataTable dt = new DataTable();//存放查出的数据
dt.Columns.Add("ID", typeof(System.Int32));
dt.Columns.Add("Name", typeof(System.String));
for (int i = 0; i < name.Length; i++)
{
DataRow row = dt.NewRow();
row[0] = i + 1;
row[1] = name[i];
dt.Rows.Add(row);
}
ddl.DataSource=dt;
ddl.DataTextField = "Name";//自己写需要的
ddl.DataValueField = "ID";
ddl.DataBind();
}
protected void dlTest_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddltest = e.Item.FindControl("drpTest") as DropDownList;
BindDrp(ddltest);
}
}
((TextBox)this.m_DlCustomerInfo.FindControl("txtYiJi")).DataTextField = "Category";
((TextBox)this.m_DlCustomerInfo.FindControl("txtYiJi")).DataValueField = "Id";
((TextBox)this.m_DlCustomerInfo.FindControl("txtYiJi")).DataBind();
那如果DATALIST里文本框控件绑定数据源,报错。
请问怎么改?