Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView hide drop-down box for a particular row

Reply
Thread Tools

GridView hide drop-down box for a particular row

 
 
Mel
Guest
Posts: n/a
 
      02-23-2009
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()
 
Reply With Quote
 
 
 
 
MLightsOut
Guest
Posts: n/a
 
      02-24-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the value of a particular field in the currently edited gridview row Mark B ASP .Net 1 08-27-2008 03:24 AM
Gridview row databound event - can't get past the 1st row of gridview maurban@gmail.com ASP .Net 5 10-13-2006 09:37 PM
Can you hide the contents of a row but leave the row there? UJ ASP .Net Datagrid Control 1 05-02-2006 06:48 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
Underline a whole row for a particular row news.microsoft.com ASP .Net Datagrid Control 5 03-06-2005 12:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57