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
Solved

itemtemplate with button and parameters to enable/disable button control

Posted on 2007-03-27
5
300 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

838 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