Gridview ButtonFields - disabling based on same row data contion?

J

jobs

Say I have Gridview with some Buttonfields I want to enable or disable
based on the values of other bound data? Here I want I only want to
enable button Rate only if field lastAction = "Export Completed"

If this can't be done at the time I first bind, and I must use
Findcontrol and by value, How can I do that?


<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:ButtonField ButtonType="Button" Text="Rate"
HeaderText="Rate" CommandName="Rate" >
</asp:ButtonField>
<asp:ButtonField ButtonType="Button" Text="Export"
HeaderText="Export" CommandName="Export">
</asp:ButtonField>
</Columns>
</asp:GridView>
 
S

Shahzad Godil

You can use something like

<asp:ButtonField ButtonType="Button" Text="Rate" HeaderText="Rate"
CommandName="Rate" Enabled=<%# IIF(Container.DataItem("lastAction ") =
"Export Completed", "true","false" %>
Shahzad Godil
Karachi-Pakistan.
 
J

jobs

Shahzad said:
You can use something like

<asp:ButtonField ButtonType="Button" Text="Rate" HeaderText="Rate"
CommandName="Rate" Enabled=<%# IIF(Container.DataItem("lastAction ") =
"Export Completed", "true","false" %>

That really looked promising and powerful. However getting Getting
error:

ButtonField does not have a Databinding Event.
 
J

jobs

I was able to get this to work:

<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Button ID="Rate2" Text="Rate2" CommandName="Rate2"
Enabled='<%# IIF(Container.DataItem("LastAction").TRIM = "PENDING
APPROVAL...","TRUE","FALSE") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>

Howevever, when I call the button, I'm unable to identify the row I'm
working with as follows now:

If e.CommandName = "Rate2" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = PendingGridView.Rows(index)
Response.Write(row.Cells(3).Text)
End If

Giving me an error about the

Input string was not a correct format.

The above row logic worked fine when using FieldButton. Will I have no
choice but to use Findcontrol now?

Thanks!
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top