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

时间:2014-12-31 11:07:00

标签: c# asp.net

.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代码:

protected void LinkBut​​ton1_Click(object sender,EventArgs e)     {

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

2 个答案:

答案 0 :(得分:0)

你在服务器端写过这个吗

Protected Void LinkButton1_Click(object sender, EventArgs e)
{

//Your server side code

}

答案 1 :(得分:0)

你必须尝试使用​​Button而不是Linkbutton..Button在嵌套转发器中正常工作..