Solved

itemtemplate with button and parameters to enable/disable button control

Posted on 2007-03-27
5
295 Views
Last Modified: 2007-12-19
ASP.net Gridview...  How can I enable / disable a buton in a cell of a gridvew control on an asp.net page?  I'm sure it will involve the itemtemplate... but I'm finding it difficult to find a good refernece on its use.

Scenario:
Button   -  Shpped  -  123 Main Street... bla bla bla
Button  -  PENDING  -  435 Main Street... bla bla bla

I want the button to show up... but be disabled... of maybe I'll greate another image, too for a 'grayed-out' button... but I want the button disabled based on the status field... this grid is connected to a sqldatasource... Please show me detail...

Thanks!!!
0
Comment
Question by:zebasdad
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:igor_alpha
Comment Utility
Hi zebasdad,
You have to add event handler to RowDataBound event of GridView. On event handel you would check out status field and set button field to disabled or not:

protected void gvYourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv  = e.Row.DataItem as DataRowView;
                if (drv["status"].ToString()=="PENDING")
                {
                    ((Button) e.Row.Cells[0].Controls[0]).Enabled = false;
                }
            }
        }
0
 

Author Comment

by:zebasdad
Comment Utility
Can you translate to VB,  please?
0
 

Author Comment

by:zebasdad
Comment Utility
I came up with this... but I'm getting an error: Type 'DataRowView' is not defined... ??

Protected Sub gvYourGrid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim drv As DataRowView = CType(e.Row.DataItem,DataRowView)
            If (drv("status").ToString = "PENDING") Then
                CType(e.Row.Cells(0).Controls(0),Button).Enabled = false
            End If
        End If
    End Sub

0
 
LVL 15

Accepted Solution

by:
igor_alpha earned 250 total points
Comment Utility
DataRowView contained in System.Data assembly.
Import System.Data or use Fully Qualified Naming such as System.Data.DataRowView.
0
 

Author Comment

by:zebasdad
Comment Utility
THANKS... THAT WORKED WELL... I HAD TO INCLUDE .TRIM ON THE ' If (drv("status").ToString ' STATEMENT... AND ALSO I HAD TO ACTUALLY CLICK ON THE LIGHTENING BOLT TO ASSIGN THE EVENT... BUT AFTER ALL THAT, IT'S DOING EXACTLY WHAT I WANT IT TO...   NOW I'M WORKING ON INCORPORATING A MOUSEOVER EVENT TO DISPLAT A FIELD - NOTES...

THANKS!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now