[英]Linkbutton in a Datalist in a GridView
I have an interesting ASP/VB.NET problem. 我有一个有趣的ASP / VB.NET问题。 I have a gridview where each row has its own datalist in a template column.
我有一个gridview,其中每一行在模板列中都有自己的数据列表。 I want to add to each item in the datalist a linkbutton that will trigger an event based on data in the datalist.
我想向数据列表中的每个项目添加一个链接按钮,该按钮将基于数据列表中的数据触发事件。 But I'm not sure how to do it.
但是我不确定该怎么做。 It's in a project so it has the designer file which does list the gridview but not the datalist inside the gridview.
它在项目中,因此具有设计器文件,该文件确实列出了gridview,但没有列出gridview中的数据列表。 When I try to add it, the listing for the datalist is removed later on when I compile.
当我尝试添加它时,稍后会在编译时删除数据列表的列表。
My question is now do I get the linkbutton in the datalist in the gridview to do something? 我的问题是,现在我可以在gridview的数据列表中获取linkbutton来做什么吗?
<asp:GridView ID="gvCmteNom" runat="server" AutoGenerateColumns="False" showheader="true" HeaderStyle-BackColor="Silver" Width="1600px">
<Columns>
<asp:TemplateField HeaderText="CURRENT SERVICE">
<ItemTemplate>
<asp:TextBox ID="txtID" runat="server" Text='<%# Bind("NOMINEE_ID") %>' Visible="False" Width="25px" />
<asp:DataList ID="dlCurrentCmtes" runat="server" DataSourceID="dsCurrentCmte" RepeatLayout="Flow" DataKeyField="ID" RepeatDirection="Horizontal">
<ItemTemplate>
<asp:HiddenField runat="server" ID="hdnUserID" Value='<%# Eval("ID") %>' />
<asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' />
<asp:LinkButton runat="server" ID="lbIncrementYear" CommandName="IncrementYear" CommandArgument='<%# Eval("ProductID") %>' Text="Add Year" />
</ItemTemplate>
<SeparatorTemplate><br /><br /></SeparatorTemplate>
</asp:DataList>
<asp:SqlDataSource ID="dsCurrentCmte" runat="server"
ConnectionString=""
ProviderName="System.Data.SqlClient" SelectCommand="spCmteList" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtID" Name="ID" PropertyName="Text" Type="String" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Two options: 两种选择:
Option 1 Specify the ItemCommand event handler for the DataList and use that to respond to the event: 选项1为DataList指定ItemCommand事件处理程序,并使用它来响应事件:
<asp:DataList OnItemCommand="Item_Command" />
Then specify that function in the code behind: 然后在后面的代码中指定该函数:
Sub Item_Command(sender As Object, e As DataListCommandEventArgs)
If e.CommandName = "IncrementYear" Then
...
End If
End Sub
Option 2 Specify the OnClick eventhandler for the link button 选项2为链接按钮指定OnClick事件处理程序
<asp:LinkButton OnClick="LinkButton_Click" runat="server"/>
Then 然后
Sub LinkButton_Click(sender As Object, e As EventArgs)
...
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.