473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Gridview ButtonFields - disabling based on same row data contion?

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>

Oct 16 '06 #1
3 12213

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.

"jobs" <jo**@webdos.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
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>

Oct 17 '06 #2

Shahzad Godil wrote:
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.

Oct 17 '06 #3
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!

Oct 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James Walker | last post by:
Hi there - hoping someone can help me here! I have a database that has been underperforming on a number of queries recently - in a test environment they take only a few seconds, but on the live...
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
0
by: xmldig | last post by:
dot net 2.0 I have a gridview and I want to add a seperator line between rows of varying col1 values... Here is an example. col1 col 2 1 A 1 B 1 C <<INSERT SEPERATOR BAR HERE>>
1
by: Hardik Shah | last post by:
Hi, I have created a entry module with data binding , I have two combo box with same data adapter with same data set. when I change the first combobox's value, there is automatically changed to...
3
by: Rob Roberts | last post by:
Is there any way to add attributes to GridView ButtonFields? I'm looking for a way to add event handlers to ButtonFields. With regular ASP.NET buttons, I can add event handlers by using the...
3
by: Subrat Das | last post by:
Hi, I have a java application which calls a stored procedure to insert data into a table.Multiple threads of java call the same procedure at the same time. Sometimes it happens that few threads send...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
2
by: Alexio | last post by:
Sample code snippet - <td align="right">Check Amount:&nbsp;</td> (1) <td><input type="text" name="CHK_input_1" size="19"style="text-align:right" onkeyup="calcCB();"...
5
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.