Referencing BoundField Datafield of Gridview when button on row is selected???

J

jobs

Given the Gridview below:

When I select the button "Rate" and fall into this code. How can I
reference "carriercode" and others . Apparently selecting the button
does not select the row. I've tried find control, and everything
returns that I must reference and instance of the object.
CommandArgument is being sent corrently. If the button where a
ButtunField I apparently I could get the get the index, But I need the
button to be an asp.net button so that I can disable based on a
condition.


Protected Sub PendingGridView_RowCommand(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
PendingGridView.RowCommand

If e.CommandName = "Rate" Then
ProcessId = e.CommandArgument
Response.Write(ProcessId)

'disregard failed attempts below
'CType(PendingGridView.FindControl("CarrierCode"),
Label).Text = ""
'Dim x As String
'x = CType(PendingGridView.Rows(0).Cells(1).Controls(0),
DataKey .tostring()
'Dim selectRow As GridViewRow = PendingGridView.SelectedRow
'Dim xx As String = selectRow.Cells(3).Text
'Response.Write(xx)


=== snip

<asp:GridView ID="PendingGridView" runat="server"
DataSourceID="PendingSqlDataSource"
AutoGenerateColumns="False" DataKeyNames="ProcessId,DayTag"
SkinID="GridView" Width="600px">
<Columns>
<asp:BoundField DataField="ProcessId" visible=false />
<asp:BoundField DataField="DayTag" HeaderText="Day Tag"
ReadOnly="True" SortExpression="DayTag" />
<asp:BoundField DataField="CarrierCode"
HeaderText="Carrier Code" SortExpression="CarrierCode" />
<asp:BoundField DataField="LastAction"
HeaderText="Last Action" SortExpression="LastAction" />
<asp:BoundField DataField="TotalRecords"
HeaderText="Total Records" SortExpression="TotalRecords" />
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:Button ID="Rate" Text="Rate"
CommandArgument='<%#Eval("ProcessId") %>' CommandName="Rate"
Enabled='<%# IIF (( (Container.DataItem("ProcessStateId") = 0) or
(Container.DataItem("ProcessStateId") = 2) or
(Container.DataItem("ProcessStateId") = 4) ) ,"TRUE","FALSE") %>'
runat="server" />
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Export">
<ItemTemplate>
<asp:Button ID="Export" Text="Export"
CommandArgument='<%#Eval("ProcessId") %>' CommandName="Export"
Enabled='<%# IIF(Container.DataItem("ProcessStateId") =
3,"TRUE","FALSE") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
 
V

vantrinh81

You can reference the selected row by:
Dim selectedRow as GridViewRow = Ctype(CType(sender,
Button).Parent.Parent, GridViewRow)
And from here you can access other cells within selectedRow.

Hope this help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top