列表视图中的DropDownList SelectedindexChanged不起作用

时间:2017-10-01 09:01:54

标签: c# asp.net

我遇到了问题,尝试了一些解决方案,但没有用。 我有一个列表视图,在其中,在ItemDateBound事件中我动态绑定几个下拉列表现在我需要绑定DropDownList SelectedindexChanged中的另一个ddl但它不会触发。 1:自动回发是真的。 2:启用视图状态模式。 3:启用视图状态为true。 4:在列表视图中ItemDateBound我将新的EventHandler(SelectedindexChanged)添加到该ddl。

<asp:ListView ID="lsvTest" runat="server" ClientIDMode="Static" OnItemDataBound="lsvTest_ItemDataBound" >
    <ItemTemplate>
        <div class="form-group">
            <label class="control-label col-sm-3" for="email">به بخش :</label>
            <div class="col-sm-6">
                <asp:DropDownList ID="cboDepartment" runat="server" CssClass="form-control" ClientIDMode="Static" DataTextField="Title" DataValueField="ID" OnSelectedIndexChanged="cboDepartment_SelectedIndexChanged"  AppendDataBoundItems="true" AutoPostBack="true"  ></asp:DropDownList>
            </div>

            <div class="col-sm-3" id="divWarningDepartment" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفا بخش مربوطه را انتخاب نمایید.</span>
            </div>
        </div>

        <div class="form-group" id="divSoftware" style="display: block" clientidmode="static" runat="server">
            <label class="control-label col-sm-3" for="email">نرم افزار مرتبط :</label>
            <div class="col-sm-6">
                <asp:DropDownList class="form-control" ID="cboSoftware" runat="server" DataTextField="Title" DataValueField="ID"></asp:DropDownList>
            </div>

            <div class="col-sm-3" id="divWarningSoftware" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفا نرم افزار مورد نظر را انتخاب نمایید.</span>
            </div>
        </div>

        <div class="form-group" id="divKarbarMarboote" runat="server">
            <label class="control-label col-sm-3" for="email">کاربر :</label>
            <div class="col-sm-6">
                <asp:DropDownList class="form-control" ID="cboKarbarMarboote" runat="server" DataTextField="Title" DataValueField="ID"></asp:DropDownList>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-3" for="email">موضوع :</label>
            <div class="col-sm-6">
                <input type="text" runat="server" class="form-control " id="txtSubject" placeholder="" dir="rtl" />
            </div>

            <div class="col-sm-3" id="divWarningSubject" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفا موضوع پیام را وارد نمایید.</span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-3" for="email">پیام :</label>
            <div class="col-sm-6">
                <textarea class="form-control" dir="rtl" id="txtMessage" runat="server" rows="5"></textarea>
            </div>

            <div class="col-sm-3" id="divWarningMessage" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفاپیام خود را درج نمایید.</span>
            </div>
        </div>

        <div class="form-group" id="divMizanAhamiat" runat="server">
            <label class="control-label col-sm-3" for="email">میزان اهمیت :</label>
            <div class="col-sm-6">
                <asp:DropDownList ID="cboMizanAhamiyat" runat="server" class="form-control">
                    <asp:ListItem Value="0">انتخاب ...</asp:ListItem>
                    <asp:ListItem Value="1">بحرانی</asp:ListItem>
                    <asp:ListItem Value="2">بالا</asp:ListItem>
                    <asp:ListItem Value="3">عادی</asp:ListItem>
                    <asp:ListItem Value="4">پایین</asp:ListItem>
                </asp:DropDownList>
            </div>

            <div class="col-sm-3" id="divWarningMizanAhamiat" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفا میزان اهمیت را انتخاب نمایید.</span>
            </div>
        </div>

        <div class="form-group" id="divMohlat" runat="server">
            <label class="control-label col-md-3 " style="" for="txtMohlatAnjam">مهلت انجام :</label>
            <div class="col-sm-2">
                <div class="input-group">
                    <input type="text" class="form-control" runat="server" id="txtMohlatAnjam" placeholder="تاریخ" />
                    <span class="input-group-addon" style="background-color: #00CC33"><i class="glyphicon glyphicon-calendar" style="color: white"></i></span>
                </div>
            </div>

            <label class="control-label col-sm-2" for="email">مدت زمان انجام :</label>
            <div class="col-sm-1  col-md-1">
                <input type="text" runat="server" class="form-control working_hour" id="txtSaatModatZaman" placeholder="ساعت" dir="ltr" maxlength="2" />
            </div>

            <label class="control-label" style="float: right">:</label>
            <div class="col-sm-1  col-md-1">
                <input type="text" runat="server" class="form-control working_hour" id="txtRoozModatZaman" placeholder="روز" dir="ltr" maxlength="2" />
            </div>

            <div class="col-sm-3" id="divWarningZaman" runat="server" style="display: none; font-size: 16px; padding-top: 4px">
                <span class="label label-danger">لطفا مهلت و مدت زمان را وارد نمایید.</span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-3">فایل الحاقی :</label>
            <div class="col-sm-4" style="padding-left: 0px">
                <div class="input-group">
                    <span class="input-group-btn">
                        <span class="btn btn-default ">
                            <asp:FileUpload ID="fileUpload" runat="server" Style="background-color: white; direction: rtl" onchange="onchangeUpload()" />
                        </span>
                    </span>

                    <div id="divUpload" runat="server" style="float: right; display: none">
                        <div style="padding: 8px 8px 0 0; float: right">
                            <asp:LinkButton ID="lnkDownload" runat="server"><i style="color:forestgreen" class="glyphicon glyphicon-download-alt"></i></asp:LinkButton>
                        </div>

                        <div style="padding: 8px 8px 0 0; float: right">
                            <asp:LinkButton ID="lnkDelete" runat="server"><i style="color:red" class="glyphicon glyphicon-trash"></i></asp:LinkButton>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-sm-3" id="divWarningAttachment" runat="server" style="display: block; font-size: 16px; padding-top: 4px">
                <span class="label label-danger" id="spWarningAttachment" runat="server"></span>
            </div>
        </div>
    </ItemTemplate>
</asp:ListView>  

protected void Page_Load(object sender, EventArgs e)
{
    lsvTest.DataSource = MyList;
    lsvTest.DataBind();
}

protected void lsvTest_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    DropDownList cboDepartment = (DropDownList)e.Item.FindControl("cboDepartment");
    var deps = from a in dc.Departments
    select new
    {
        ID = a.ID,
        Title = a.Title,
    };

    cboDepartment.DataSource = deps;
    cboDepartment.DataBind();

    DropDownList cboSoftware = (DropDownList)e.Item.FindControl("cboSoftware");
    var sw = from a in dc.Softwares
    select new
    {
        ID = a.ID,
        Title = a.Title,
    };

    cboSoftware.DataSource = sw;
    cboSoftware.DataBind();

    if (cboDepartment != null)
    {
        cboDepartment.SelectedIndexChanged += new EventHandler(cboDepartment_SelectedIndexChanged);
    }
}

protected void cboDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
    //bind another dropdown list
}

0 个答案:

没有答案