本文介绍了中继器控制链接按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我的代码: < asp:SqlDataSource ID = dsCollections runat = server ConnectionString = <% $ ConnectionStrings:csConnectionString %> SelectCommand = SELECT [CategName],[Id] FROM [Category] > < / asp:SqlDataSource > < asp:Repeater ID = Repeater1 runat = server > < ItemTemplate > < asp:LinkButton ID = LinkButton1 runat = server OnCommand = LinkButton1_Command CommandName = MyUpdate CommandArgument = ' <% #Eval( CategName)%> ' > LinkButton < / asp:LinkButton > < / ItemTemplate > < / asp:Repeater > asp.net代码: protected void LinkButton1_Command( object sender,CommandEventArgs e) { if (e.CommandName == MyUpdate) { Response.Write( 工作); } } 解决方案 ConnectionStrings:csConnectionString %> SelectCommand = SELECT [CategName],[Id] FROM [Category] > < / asp:SqlDataSource > < asp:Repeater ID = Repeater1 runat = 服务器 > < ItemTemplate > < asp:LinkButton ID = LinkButton1 runat = 服务器 OnCommand = LinkButton1_Command CommandName = MyUpdate CommandArgument =' <% #Eval( CategName)%> ' > LinkButton < / asp:LinkButton > < / ItemTemplate > < / asp:重复r > asp.net代码: b $ b 受保护 void LinkButton1_Command( object sender,CommandEventArgs e) { if ( e.CommandName == MyUpdate) { Response.Write( work); } } 我认为你应该绑定来自代码的数据... 因为它的工作.. DataTable dt = new DataTable(); dt.Columns.Add( CategName); for ( int i = 0 ; i < 10 ; i ++) { dt.Rows .Add( CategName + i); } Repeater1.DataSource = dt; Repeater1.DataBind(); 如果那是一个Repeater Control,那么你可以尝试定义 Repeater.ItemCommand Event [ ^ ]。 my code:<asp:SqlDataSource ID="dsCollections" runat="server" ConnectionString="<%$ ConnectionStrings:csConnectionString %>" SelectCommand="SELECT [CategName], [Id] FROM [Category]"></asp:SqlDataSource> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("CategName") %>'>LinkButton</asp:LinkButton> </ItemTemplate></asp:Repeater>asp.net code:protected void LinkButton1_Command(object sender, CommandEventArgs e) { if (e.CommandName == "MyUpdate") { Response.Write("work"); } } 解决方案 ConnectionStrings:csConnectionString %>" SelectCommand="SELECT [CategName], [Id] FROM [Category]"></asp:SqlDataSource> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("CategName") %>'>LinkButton</asp:LinkButton> </ItemTemplate></asp:Repeater>asp.net code:protected void LinkButton1_Command(object sender, CommandEventArgs e) { if (e.CommandName == "MyUpdate") { Response.Write("work"); } }i think you should bind the data from code behind...because its working..DataTable dt = new DataTable(); dt.Columns.Add("CategName"); for (int i = 0; i < 10; i++) { dt.Rows.Add("CategName" + i); } Repeater1.DataSource = dt; Repeater1.DataBind();If that is a Repeater Control, then you can try defining the Repeater.ItemCommand Event[^]. 这篇关于中继器控制链接按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 15:30