C# 如何编辑Repeater控件中的下拉项
在这里,我在中继器控件中添加了一个DropDownList, 为此,一个DataTable被指定为数据源 但是我想根据数据源数据编辑DropDownList.Items 意味着如果数据源将给出3个数据,则DropDownList具有1,2,3中的列表项 如果是5,那么像这样的1,2,3,4,5C# 如何编辑Repeater控件中的下拉项,c#,.net,asp.net,drop-down-menu,repeater,C#,.net,Asp.net,Drop Down Menu,Repeater,在这里,我在中继器控件中添加了一个DropDownList, 为此,一个DataTable被指定为数据源 但是我想根据数据源数据编辑DropDownList.Items 意味着如果数据源将给出3个数据,则DropDownList具有1,2,3中的列表项 如果是5,那么像这样的1,2,3,4,5 因此,对于我必须使用的事件和我应该编写的代码?在您的中继器的项databound中,找到您的控件,并绑定到数据库,或设置值,或任何您想要的,如下所示: protected void Repeater1_I
因此,对于我必须使用的事件和我应该编写的代码?在您的
中继器的项databound
中,找到您的控件,并绑定到数据库,或设置值,或任何您想要的,如下所示:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView row = e.Item.DataItem as DataRowView;
DropDownList dl = e.Item.FindControl("ddlCategory") as DropDownList;
dl.DataSource = CategoriesDataTable;
dl.DataTextField = "CategoryDescription";
dl.DataValueField = "CategoryPK";
dl.SelectedValue = row["CategoryFK"].ToString();
dl.DataBind();
}
protectedvoid rpt_ItemDataBound(对象发送方,RepeaterItemEventArgs e)
{
如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem)
{
整数计数=0;
//set count=您的数据表计数
DropDownList ddl=(DropDownList)e.Item.FindControl(“ddl”);
对于(int i=1;i
protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
int count = 0;
// set count = your datatable count
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl");
for(int i=1;i<=count;i++)
{
ddl.Items.Add(i.ToString());
}
}
}