zebasdad
asked on
itemtemplate with button and parameters to enable/disable button control
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!!!
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!!!
ASKER
Can you translate to VB, please?
ASKER
I came up with this... but I'm getting an error: Type 'DataRowView' is not defined... ??
Protected Sub gvYourGrid_RowDataBound(By Val sender As Object, ByVal e As GridViewRowEventArgs)
If (e.Row.RowType = DataControlRowType.DataRow ) Then
Dim drv As DataRowView = CType(e.Row.DataItem,DataR owView)
If (drv("status").ToString = "PENDING") Then
CType(e.Row.Cells(0).Contr ols(0),But ton).Enabl ed = false
End If
End If
End Sub
Protected Sub gvYourGrid_RowDataBound(By
If (e.Row.RowType = DataControlRowType.DataRow
Dim drv As DataRowView = CType(e.Row.DataItem,DataR
If (drv("status").ToString = "PENDING") Then
CType(e.Row.Cells(0).Contr
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
THANKS!
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(ob
{
if (e.Row.RowType == DataControlRowType.DataRow
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (drv["status"].ToString()=
{
((Button) e.Row.Cells[0].Controls[0]
}
}
}