Solved

itemtemplate with button and parameters to enable/disable button control

Posted on 2007-03-27
5
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:igor_alpha
ID: 18804398
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
ID: 18819533
Can you translate to VB,  please?
0
 

Author Comment

by:zebasdad
ID: 18819573
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
ID: 18820138
DataRowView contained in System.Data assembly.
Import System.Data or use Fully Qualified Naming such as System.Data.DataRowView.
0
 

Author Comment

by:zebasdad
ID: 18822717
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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