请问为何执行一个reapeater里面的button的click的时候会先把我之前点击过的dropdownlist 的select事件先执行一遍,然后才会执行button的click,怎样才能只执行click事件? 有没有人遇到过同样问题?希望能有人帮忙解决 谢谢!

解决方案 »

  1.   

    前台代码:
    <asp:repeater id="Repeater1" runat="server" enableviewstate="False" onitemcommand="Repeater1_ItemCommand">
    <ItemTemplate>        
    处理人:
    <asp:DropDownList ID="areas" runat="server" thisIndex="<%# Container.ItemIndex %>"  OnSelectedIndexChanged="SelectedIndexChanged_area" AutoPostBack="true">
                                                
    <asp:ListItem Value="">--选择--</asp:ListItem>
    <asp:ListItem Value="a">a</asp:ListItem>
    <asp:ListItem Value="b">b</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList ID="handler" runat="server">
    </asp:DropDownList>
                                       
    选择类型:
    <asp:DropDownList ID="big_type"  runat="server" thisIndex="<%# Container.ItemIndex %>"  OnSelectedIndexChanged="SelectedIndexChanged_type" AutoPostBack="true">
    <asp:ListItem Value="">--选择类型--</asp:ListItem>
    <asp:ListItem Value="a">a</asp:ListItem>
    <asp:ListItem Value="b">b</asp:ListItem>
    </asp:DropDownList>
    小类型:
    <asp:DropDownList ID="small_type" runat="server">
    </asp:DropDownList><asp:ImageButton ID="ImageButton1" runat="server" 
    ImageUrl="~/images/gengxin.jpg" CommandName="time" ValidationGroup="<%# Container.ItemIndex %>"/>
    </ItemTemplate>
    </asp:repeater>后台:
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                switch (e.CommandName)
                {                case "time":
                       <这里是我的执行代码>
                }        }        protected void SelectedIndexChanged_area(object sender, EventArgs e)
            {
                DropDownList dl = sender as DropDownList;
                int i = int.Parse(dl.Attributes["thisIndex"]);
                    DropDownList areas = (DropDownList)Repeater1.Items[i].FindControl("areas");
                    DropDownList handler = (DropDownList)Repeater1.Items[i].FindControl("handler");
                    DataTable dt = Getdata.data(areas.SelectedItem.Value);
                    handler.DataSource = dt;
                    handler.DataTextField = dt.Columns["name"].ToString();
                    handler.DataValueField = dt.Columns["name"].ToString();
                    handler.DataBind();//绑定数据库
            }
            protected void SelectedIndexChanged_type(object sender, EventArgs e)
            {
                DropDownList dl = sender as DropDownList;
                int i = int.Parse(dl.Attributes["thisIndex"]);
                    DropDownList big_type = (DropDownList)Repeater1.Items[i].FindControl("big_type");
                    DropDownList small_type = (DropDownList)Repeater1.Items[i].FindControl("small_type");
                    DataTable dt = Getdata.data(big_type.SelectedItem.Value);
                    small_type.DataSource = dt;
                    small_type.DataTextField = dt.Columns["name"].ToString();
                    small_type.DataValueField = dt.Columns["name"].ToString();
                    small_type.DataBind();//绑定数据库
            }
      

  2.   

    可以考虑用一个隐藏的标识来标识事件是不是需要执行select事件。
      

  3.   

    <asp:ImageButton ID="ImageButton1" runat="server"  Click="ImageButton1_Click"
    ImageUrl="~/images/gengxin.jpg" CommandName="time" ValidationGroup="<%# Container.ItemIndex %>"/>
       
     private void ImageButton1_Click(object sender, EventArgs e)
    {
    response.write("ok");
    }
      

  4.   

    就是奇怪为什么我点击button会触发其他事件 是itemchange的问题么
      

  5.   

    将dropdownlist的AutoPostBack属性设为true
      

  6.   

    大哥 我贴了代码出来啦 是true
      

  7.   

    很奇怪。。呵呵

    <asp:ImageButton ID="ImageButton1" runat="server" 
    ImageUrl="~/images/gengxin.jpg" CommandName="time" ValidationGroup="<%# Container.ItemIndex %>"/>
    </ItemTemplate>
    赋个事件