嵌套中继器控制链接按钮在 asp.net 中不起作用

本文关键字:asp net 不起作用 按钮 中继器 控制 链接 嵌套 | 更新日期: 2023-09-27 18:35:49

.ascx 页面中的嵌套转发器链接按钮

我的代码:

   <asp:Repeater ID="rptrCategory" DataSourceID="dsCollections" runat="server" >                   
     <ItemTemplate>   
        <li id="l1" runat="server"  class='<%#Eval("CategName") %>'>                                                             
        <asp:Repeater id="rptrTypes" DataSourceID="dsTypes" runat="server"   >                                       
          <ItemTemplate> 
            <li id="current">
            <asp:LinkButton ID="LinkButton1" runat="server" style="color:#000; text-decoration:none;"  OnClick="LinkButton1_Click"><%# Eval("SubCategName")%></asp:LinkButton>
          </ItemTemplate>                                        
        </asp:Repeater>
        <asp:SqlDataSource ID="dsTypes" runat="server" ConnectionString="<%$ ConnectionStrings:csConnectionString %>"
        SelectCommand="SELECT SubCategory.SubCategName,Category.CategName, SubCategory.Id, SubCategory.CategId FROM Category INNER JOIN SubCategory ON Category.Id = SubCategory.CategId where Category.Id= @categ">
          <SelectParameters>                
            <asp:ControlParameter Name="categ" ControlID="hfId" PropertyName="Value" />
          </SelectParameters>
        </asp:SqlDataSource>   
     </ItemTemplate>                        
   </asp:Repeater>
   <asp:SqlDataSource ID="dsCollections" runat="server" ConnectionString="<%$ ConnectionStrings:csConnectionString %>"
         SelectCommand="SELECT [CategName], [Id] FROM [Category]"></asp:SqlDataSource>

asp.net 代码:

受保护的无效LinkButton1_Click(对象发送器,事件参数 e) {

    Response.Redirect("index.aspx");
}

嵌套中继器控制链接按钮在 asp.net 中不起作用

你在服务器端写的吗

Protected Void LinkButton1_Click(object sender, EventArgs e)
{
//Your server side code
}

您必须尝试 Button 而不是 Linkbutton。按钮在嵌套中继器中工作正常。.