Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filter sql results in datagrid

Status
Not open for further replies.

GHOST24

Programmer
Jul 7, 2005
22
GB
I have a program that queries a database and returns the values that are entered as the user goes along, the results are returned for a final check in a datagrid.
I have bound the columns so I get only the results that I need but I want to know if there is a way to show only the bound columns that have data returned to them.
for example the user orders three red items but no white ones I would like to show the column for the red items only but if the user wanted three red and three white I would need to show the red and white columns unfortunately I cant use the "select *" statement because there are field the user should not see.
Hope this makes sense.
 
In the ItemDataBound and ItemCreated events, you could modify the look of the datagrid to not show particular columns.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
can you do it when the results are returned from the database.
I will not know what has been ordered in advance
I don't want to show empty columns in the datagrid
 
Yes, you can. Simply check the Text of each Cell and if it's empty, hide it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
can you please give me an example.
I take it some kind of loop checking each cell but not sure how.
 
As I said above, you can use the ItemCreated and ItemDataBound events so you don't need any sort of loop as these fire each time an item is created. You can then just check the text of the relevant cell e.g.
Code:
e.Item.Cells(0).Text


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I do not know how to look at each cell as i have never done this before and cannot find any book examples, the datagrid is loaded with the page load event using the code below.

sqlconnection1.open()
sqldataadapter1.fill(ds1)
sqlconnection1.close()

DataGrid1.DataSource = ds1
DataGrid1.DataKeyField = "id"
DataGrid1.DataBind()

so if i check to see if there is text in the cell i would
use what?
I cannot use if e.item.cells(0).text = "" then
do something here

because the e is not declared.
 
ca8msm said:
you can use the ItemCreated and ItemDataBound events
e.g.
Code:
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top