?
Solved

itemtemplate with button and parameters to enable/disable button control

Posted on 2007-03-27
5
Medium Priority
?
304 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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