如何在转发器中的Web用户控件中填充下拉列表 [英] how to populate dropdownlist in web user control in a repeater

查看:78
本文介绍了如何在转发器中的Web用户控件中填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有用户控制权,其中包含:

一个下拉列表na文本框。



i必须填充用户控件中的下拉列表n必须写入onselectedindexchange来填充用户控制它自己的事件的文本框。



n



我将这个Web用户控件放在ASP.NET的转发器中。



i努力填充用户控件的cs文件中的下拉列表

但它无效。



Plzzz给出一些建议/帮助我...



 protected void Repeater2_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
int index = 0;
if(Repeater1.Items [index] .ItemType == ListItemType.Item || Repeater1.Items [index] .ItemType == ListItemType.AlternatingItem)
{
if(Repeater1.Items [索引] .FindControl(Repeater2)!= null)
{

Repeater r = Repeater1.Items [index] .FindControl(Repeater2)作为Repeater;

foreach(r.Items中的RepeaterItem项目)
{
UserControl u =(UserControl)item.FindControl(SubChemicals1);

if(u!= null)
{

// if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType = = ListItemType.AlternatingItem)
// {
DropDownList d =(DropDownList)u.FindControl(ddlchemicals);
d.DataTextField =CName;
d.DataValueField =RecID;
d.DataSource = bl.Fill_DDL(Sp_GetSubChemicals);
d.DataBind();
d.Items.Insert(0,new ListItem(--- Select ---,0));


//}
}

}
}
}
}





我知道了,但事情是,我有更多的嵌套转发器

这个下拉列表所在的位置

仅在第一个嵌套转发器中填充但不包含其他转发器....



谢谢

解决方案

int index = 0;



它解释了你的问题。

我也觉得你的ItemDataBound事件都错了。



 受保护  void  Repeater2_ItemDataBound( object  sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType!= ListItemType.Item
& ;& e.Item.ItemType!= ListItemType.AlternatingItem)
{
return ;
}


UserControl u =(UserControl)e.item.FindControl( SubChemicals1);

if (u!= null
{

DropDownList d =(DropDownList)u.FindControl( ddlchemicals);
d.DataTextField = CName;
d.DataValueField = RecID;
d.DataSource = bl.Fill_DDL( Sp_GetSubChemicals);
d.DataBind();
d.Items.Insert( 0 new ListItem( ---选择--- 0\" ));


}


}


嗨Subhan,请尝试使用此代码

< pre < span class =code-attribute> lang = c# > protected void Repeater2_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
if(e.Item) .ItemType!= ListItemType.Item
&& e.Item.ItemType!= ListItemType.AlternatingItem)
UserControl u =(UserControl)e.item.FindControl(SubChemicals1);

if(u!= null)
{

DropDownList d =(DropDownList)u.FindControl(ddlchemicals);
d.DataTextField =CName;
d.DataValueField =RecID;
d.DataSource = bl.Fill_DDL(Sp_GetSubChemicals);
d.DataBind();
d.Items.Insert(0,new ListItem(--- Select ---,0));
}

} < / pre >


Hi guys,

I have user control which contains:
one dropdownlist n a textbox.

i have to populate the dropdownlist in the user control n have to write the "onselectedindexchange" to fill the textbox which in the user control it self., event.

n

i'm placing this web user control in a repeater in ASP.NET.

i tried hard to populate the dropdownlist in the cs file of the user control
but its not working.

Plzzz give some suggestions/help me...

protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            int index = 0;
            if (Repeater1.Items[index].ItemType == ListItemType.Item || Repeater1.Items[index].ItemType == ListItemType.AlternatingItem)
            {
                if (Repeater1.Items[index].FindControl("Repeater2") != null)
                {

                    Repeater r = Repeater1.Items[index].FindControl("Repeater2") as Repeater;

                    foreach (RepeaterItem item in r.Items)
                    {
                        UserControl u = (UserControl)item.FindControl("SubChemicals1");

                        if (u != null)
                        {

                            //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                            //{
                                DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                                d.DataTextField = "CName";
                                d.DataValueField = "RecID";
                                d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                                d.DataBind();
                                d.Items.Insert(0, new ListItem("---Select---", "0"));

                                
                            //}
                        }

                    }
                }
            }
        }



I got it, but the things is, i have morethan one nested repeaters
where this dropdownlist is located n
its filling only in the 1st nested repeater only but not other repeaters....

Thanks

解决方案

int index = 0;

It explains your issue.
I also feel like you got the ItemDataBound event all wrong.

protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }


            UserControl u = (UserControl)e.item.FindControl("SubChemicals1");

            if (u != null)
            {

                    DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                    d.DataTextField = "CName";
                    d.DataValueField = "RecID";
                    d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                    d.DataBind();
                    d.Items.Insert(0, new ListItem("---Select---", "0"));


            }


        }


Hi Subhan, Please try with this code

<pre lang="c#">protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item
                && e.Item.ItemType != ListItemType.AlternatingItem)
 UserControl u = (UserControl)e.item.FindControl("SubChemicals1");

            if (u != null)
            {

                    DropDownList d = (DropDownList)u.FindControl("ddlchemicals");
                    d.DataTextField = "CName";
                    d.DataValueField = "RecID";
                    d.DataSource = bl.Fill_DDL("Sp_GetSubChemicals");
                    d.DataBind();
                    d.Items.Insert(0, new ListItem("---Select---", "0"));
             }

        }</pre>


这篇关于如何在转发器中的Web用户控件中填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆