On Feb 23, 9:10*am, Mel <MLights...@gmail.com> wrote:
> I have a gridview that is bound to a datatable. *Some rows require a
> selection be chosen from a drop-down box, called "Pitch", other rows
> do not require a pitch selection. *How do I hide the drop-down for
> those particular rows? *An example would be greatly appreciated.
>
> 'My Example Code (using asp.net 2.0, vb.net, Visual Studio 2005 Pro)
> Dim dt As DataTable
> dt = New DataTable
> dt.Columns.Add("Part Description", GetType(String))
> dt.Columns.Add("Pitch", GetType(String))
>
> Dim strUnivPartsSQL As String = "SELECT * FROM [Parts] ORDER BY [SN];"
> Dim recStdParts As System.Data.OleDb.OleDbDataReader
> Dim cmdPart As New System.Data.OleDb.OleDbCommand(strUnivPartsSQL,
> conStdParts)
> conStdParts.Open()
> recStdParts = cmdPart.ExecuteReader()
>
> Do While recStdParts.Read()
> * * * * If recStdParts("Pitch") = True Then * 'this part requires a pitch
> selection
> * * * * * * dt.Rows.Add(New String() {recStdParts("Part
> Description").ToString, "4:12"}) 'set default pitch to 4:12
> * * * * Else * *'no pitch selection is necessary, HOW DO I HIDE THE PITCH DROP-
> DOWN BOX? *THIS CODE DOES NOT WORK, IT STILL SHOWS THE DROP-DOWN BOX.
> * * * * * * dt.Rows.Add(New String() {recStdParts("Part
> Description").ToString, Nothing})
> * * * * End If
> Loop
> recStdParts.Close()
> conStdParts.Close()
> conStdParts.Dispose()
> UpdatePanel2.Update()
Nevermind, I figured it out. If the row requires a pitch I am storing
"True" or "False" in one of the cells. Then on the RowDataBound event
I simply hide the Pitch drop-down box for the rows where Pitch equals
False. Here is the code if anyone is interested:
Protected Sub gvParts_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
gvParts.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then 'only
evaluate the data rows
Dim bPitch As Boolean
bPitch = e.Row.Cells(3).Text 'retrieve the pitch setting
which is either True or False from another cell in the grid
Dim ddlPitch1 As DropDownList = e.Row.FindControl
("ddlPitch") 'get a handle on the Pitch drop-down box which has my
pitch selections in it (1:12, 2:12, 3:12,...12:12)
If Not ddlPitch1 Is Nothing Then 'If the drop-down box was
found show the pitch drop-down box if this item's pitch setting =
True.
If bPitch = True Then
ddlPitch1.Visible = True
Else
ddlPitch1.Visible = False
End If
End If
End If
End Sub
|