中继器控制链接按钮不起作用 [英] repeater control link button not working

查看:104
本文介绍了中继器控制链接按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:



 <   asp:SqlDataSource     ID   =  dsCollections    runat   =  server   < span class =code-attribute> ConnectionString   =   <% $ ConnectionStrings:csConnectionString %>   

< span class =code-attribute> SelectCommand = SELECT [CategName],[Id] FROM [Category] > < / asp:SqlDataSource >
< asp:Repeater ID = Repeater1 < span class =code-attribute> runat = server >
< ItemTemplate >
< < span class =code-leadattribute> asp:LinkBut​​ton ID = LinkBut​​ton1 runat = server OnCommand = LinkBut​​ton1_Command < span class =code-attribute> CommandName = MyUpdate CommandArgument = ' <% #Eval( CategName%> ' > LinkBut​​ton < / asp:LinkBut​​ton >
< / ItemTemplate >
< / asp:Repeater >

< br $>


asp.net代码:



  protected   void  LinkBut​​ton1_Command( object  sender,CommandEventArgs e)
{
if (e.CommandName == MyUpdate
{
Response.Write( 工作);
}
}

解决方案

ConnectionStrings:csConnectionString %>

SelectCommand = SELECT [CategName],[Id] FROM [Category] > < / asp:SqlDataSource >
< span class =code-keyword>< asp:Repeater ID = Repeater1 runat = 服务器 >
< span class =code-keyword>< ItemTemplate >
< asp:LinkBut​​ton ID = LinkBut​​ton1 runat = 服务器 OnCommand = LinkBut​​ton1_Command CommandName = MyUpdate CommandArgument =' <% #Eval( CategName%> ' > LinkBut​​ton < / asp:LinkBut​​ton >
< / ItemTemplate >
< / asp:重复r >





asp.net代码:< br $> b $ b

 受保护  void  LinkBut​​ton1_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[^].


这篇关于中继器控制链接按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆