Gridview ButtonFields - disabling based on same row data contion?

  • Thread starter Thread starter jobs
  • Start date Start date
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>
 
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.
 
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.
 
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!
 
No U don't have to

Just add the following part

CommandArgument='<%# ((System.Web.UI.WebControls.GridViewRow)(Container)).RowIndex %>'

 
Back
Top