Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我想在用户从回发页面的下拉列表中选择任何项目时立即调用函数。如何操作? 地位 接受 拒绝 代码: 受保护的void Repeater1\u ItemDataBound(对象发送方,RepeaterItemEventArgs e) { //DropDownList DropDownList1=(DropDownList)发送方; //string SelectedValue=DropDownList1.SelectedValue; 如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem) { DropDownList ddldrop=(DropDownList)e.Item.FindControl(“DropDownList1”); int value=Convert.ToInt32(ddldrop.SelectedValue); 主管sup=新主管(); 如果(值==1){ sup.Status=“接受”; sup.Save(); } } }_C#_Asp.net - Fatal编程技术网

C# 我想在用户从回发页面的下拉列表中选择任何项目时立即调用函数。如何操作? 地位 接受 拒绝 代码: 受保护的void Repeater1\u ItemDataBound(对象发送方,RepeaterItemEventArgs e) { //DropDownList DropDownList1=(DropDownList)发送方; //string SelectedValue=DropDownList1.SelectedValue; 如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem) { DropDownList ddldrop=(DropDownList)e.Item.FindControl(“DropDownList1”); int value=Convert.ToInt32(ddldrop.SelectedValue); 主管sup=新主管(); 如果(值==1){ sup.Status=“接受”; sup.Save(); } } }

C# 我想在用户从回发页面的下拉列表中选择任何项目时立即调用函数。如何操作? 地位 接受 拒绝 代码: 受保护的void Repeater1\u ItemDataBound(对象发送方,RepeaterItemEventArgs e) { //DropDownList DropDownList1=(DropDownList)发送方; //string SelectedValue=DropDownList1.SelectedValue; 如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem) { DropDownList ddldrop=(DropDownList)e.Item.FindControl(“DropDownList1”); int value=Convert.ToInt32(ddldrop.SelectedValue); 主管sup=新主管(); 如果(值==1){ sup.Status=“接受”; sup.Save(); } } },c#,asp.net,C#,Asp.net,更改: <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"> <ItemTemplate> <tr> <td><%#subtypes.FindByPk(Convert.ToInt32(Eval("Subit

更改:

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <ItemTemplate>
                    <tr>
                        <td><%#subtypes.FindByPk(Convert.ToInt32(Eval("SubitemID"))).title%></td>
                        <td><%#Eval("quantity")%></td>
                        <td><%#ThanaRecord.FindByPk(Convert.ToInt32(Eval("Thanaid"))).title%></td>
                        <td><%#Eval("created_at")%></td>
                        <td> <% if (Employee.GetCurrentEmployee().role == "Admin") { %>
                            <a href="AddDemand.aspx?type=update&id=<%#Eval("id")%>">EDIT</a>

                                <a href="AddDemand.aspx?type=delete&id=<%#Eval("id")%>">DELETE</a>
                            <% } %>
                        <%if (Employee.GetCurrentEmployee().role == "SuperVisor")
                           { %>
                          <asp:DropDownList ID="DropDownList1" runat="server" Width="120px"  AutoPostBack="false" CssClass="form-control">
                     <asp:ListItem Text="Status" Value="0">Status</asp:ListItem>
                              <asp:ListItem Text="Accept" Value="1">Accept</asp:ListItem>
                    <asp:ListItem Text="Reject" Value="2">Reject</asp:ListItem>

                </asp:DropDownList>

                            <%--<asp:textbox runat="server" id="textTest"></asp:textbox>--%>
                        </td>
                        <%} %>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
CODE:
 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //DropDownList DropDownList1 = (DropDownList)sender;
        //string SelectedValue = DropDownList1.SelectedValue;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList ddldrop = (DropDownList)e.Item.FindControl("DropDownList1");
            int  value =Convert.ToInt32( ddldrop.SelectedValue);
            Supervisor sup = new Supervisor();
        if (value == 1) {
                sup.Status = "Accept";
                sup.Save();
            }
        }
    }
这会立即触发事件

注意: 此行为创建一个
POST
,它将触发
Page\u Load
,如果在触发下拉列表事件之前在中继器上调用
DataBind()
,它将根本不会触发。确保
DataBind()
保护!IsPostback
以避免抑制事件

例如:

// event handler - this event will fire for ALL drop downs in the repeater
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

  // this will tell which drop down fired the event
  var dropdown = (DropDownList)sender;
  // this will tell you the repeater item containing the drop down
  var repeateritem = (RepeaterItem)dropdown.NamingContainer;
}

实现SelectedIndexChanged事件并将AutoPostBack设置为True。

首先,添加SelectedIndexChanged事件,并将dropdownlist控件上的AutoPostBack设置为True

然后在代码隐藏中添加以下代码,只需排除ScriptManager部分,并使用您的方法存储或显示您喜欢的任何位置

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostback)
    {
        Repeater1.DataSource = SomeDataSource; // whatever
        Repeater1.DataBind();
    }
}

AutoPostBack
必须是
True
事件处理程序才能立即启动,但dropdownlist selected index事件不会在Repeater中找到dropdown但如何在dropdown selected index change事件中找到Repeater中的dropdown值?@Hishahid很高兴我付出了所有努力来帮助您,您标记了另一个答案,即使他们是一样的,我也是第一个。我感谢你们的帮助,但我更了解那个人的代码,它对我很有用。@Hishamshaid不担心。这毕竟是你的选择。有时候会令人沮丧。特别是当你像我一样脾气暴躁的时候:)
// event handler - this event will fire for ALL drop downs in the repeater
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

  // this will tell which drop down fired the event
  var dropdown = (DropDownList)sender;
  // this will tell you the repeater item containing the drop down
  var repeateritem = (RepeaterItem)dropdown.NamingContainer;
}
protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostback)
    {
        Repeater1.DataSource = SomeDataSource; // whatever
        Repeater1.DataBind();
    }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
        DropDownList ddl = sender as DropDownList;
        RepeaterItem rptItems = ddl.NamingContainer as RepeaterItem;
        DropDownList ddlItems = rptItems.FindControl("DropDownList1") as DropDownList;
        ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "showname", "javascript: alert('" + ddlItems.SelectedItem.ToString()   + "');", true);
}