【发布时间】:2018-10-11 17:58:42
【问题描述】:
我需要在以下 gridview 的选定行上引用来自 lblCaseStatus 的标签值:
<asp:GridView ID="grdTaskList" runat="server" DataKeyNames="CaseID"
AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True"
PageSize="20">
<Columns>
<asp:BoundField DataField="Task" HeaderText="Task" SortExpression="Task"
ItemStyle-Width="350px" />
<asp:BoundField DataField="DueDate" HeaderText="Due Date" SortExpression="DueDate"
DataFormatString="{0:d}" />
<asp:TemplateField HeaderText="Case Status">
<ItemTemplate>
<asp:Label ID="lblCaseStatus" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnView" runat="server" Text="View"
CommandName="ViewIntake"
CommandArgument='<%# Eval("CaseID") %>'
Font-Bold="true" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
我在网上搜索过,但没有找到任何可行的解决方案。我尝试使用基于此 SO 答案 (https://stackoverflow.com/a/10784039/3938754) 的答案,其中包括此免责声明:
备注:这仅适用于 Boundfields。
我正在使用 TemplateField 并猜测这就是它失败的原因:
Dim id as Guid = grdTaskList.DataKeys(row.RowIndex).Value
读取错误:
指定的转换无效。 (从数字转换时,该值必须是小于无穷大的数字。)
RowIndex 和 Value 都有数据。
Private Sub grdTaskList_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdTaskList.RowCommand
If (e.CommandName = "ViewIntake") Then
Dim caseID As Integer = Int32.Parse(e.CommandArgument.ToString())
Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
Dim id As Guid = grdTaskList.DataKeys(row.RowIndex).Value
Dim caseStatus As String = CType(row.Cells(2), DataControlFieldCell).Text
Response.Redirect(IntakeSite.EditIntake.GetPageURL(caseID:=caseID, caseStatus:=caseStatus))
End If
End Sub
那么如何通过 RowCommand 方法引用 ItemTemplate 中的标签值?
提前感谢您的时间和帮助。
【问题讨论】:
标签: vb.net gridview label templatefield rowcommand