I need to reference the label value from lblCaseStatus on the selected row of the following gridview:
<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>
I have searched the web and I have not found any solutions that will work. I tried using one based on this SO answer (https://stackoverflow.com/a/10784039/3938754) which included this disclaimer:
Remark: this only works with Boundfields.
I am using a TemplateField and guessing this is why it fails on the line:
Dim id as Guid = grdTaskList.DataKeys(row.RowIndex).Value
with the error reading:
Specified cast is not valid. (When casting from a number, the value must be a number less than infinity.)
Both the RowIndex and Value have data.
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
So how do I reference the label value inside an ItemTemplate from the RowCommand method?
Thanks in advance for your time and assistance.