controlling databound ASP

G

Guest

Hi,

I'm more of a windows programmer than ASP and I've having a little
difficulty in ASP.Net (framework 2.0) - VB.net

I have a datagrid on an aspx page and the html is building the display in a
table row by row. A sample row being

<tr>
<td>Comment:</td>
<td><%# Databinder.Eval(Container.DataItem,"comment") %></td>
</tr>

I want to only write these rows where there is data. I think I need to mix
the asp <% and databound <%# elements in some way but maybe this is not going
to be possible ?

I tried to kick off by at least trying to blank out the label in the
following way (slightly desperate but I felt it might be a step in the right
direction!) but this doesn't work although I can't see why not

<%# DataBinder.Eval(Container.DataItem, "Comment").Equals("") & "":"Comment"
%>

VS is telling me a bracket is expected and thate there are 2 additional
unspecified syntax errors in this one line !

Thanks for any help on this!

Ben.
 
M

Mike

You can do this.

create a dataset for your data
bind your datagrid like this

datagrid.datasource = ds;
datagrid.databind();

that will bind your datagrid.

if you want to only show certain data items then you can specify that by
going to the properties of the grid and add the columns you want to show.
 
G

Guest

Thanks for replying. I already have a page that is successfully showing the
results in the way you have outlined. The difficulty I have is not in
disregarding columns but not adding them for the specific records where they
are blank.

So if it were Name, Address, Phone. I would show these records where they
are filled out but only name and phone on the specific records where the
address is blank.

Cheers,

Ben.
 
M

Mike

if you have a grid, its only going to show the data you have. I have
something similiar. I have a grid on my page and it shows

name, office, phone number

and even though a name may be blank or office, etc, it still shows the rest
of the data for that row.
so I may have a grid look like this at times

name office phone number
Greg Philly 555-1212
Karen Orlando
Beth 555-1234

and i'm only using the dataset for my grid, I'm not doing anything specail
for this result.
Unless I'm missing what your saying, your grid should show like above
 
M

Mike

that would work but i think he still wants to show the row even if there is
no data for all the columns

at least from what I get from this, thats what he's trying to do.

"So if it were Name, Address, Phone. I would show these records where they
are filled out but only name and phone on the specific records where the
address is blank."
 
G

Guest

I think I worded the question wrongly.

I can't use the SQL version because as Mike says I don't want to exclude the
row.

I don't have a problem showing the record when there is no data in one of
the fields.

Sorry this is my mistake but this is more of an ASP question than a datagrid
question.

The users can switch to a table view where there is one record per page in a
tabluar form build using the databinding but using template columns to show
the data in an asp table form. One row may be added like this in the asp for
example

<tr>
<td>Comment:</td>
<td><%# Databinder.Eval(Container.DataItem,"comment") %></td>
</tr>

what I would like to do is only add these individual rows where there is a
value in the field so in this case (although I would wrap all rows this way)
in pseudo code it would be

IF <%# Databinder.Eval(Container.DataItem,"comment") %> = "" then
DO nothing / move to next row...
ELSE
<tr>
<td>Comment:</td>
<td><%# Databinder.Eval(Container.DataItem,"comment") %></td>
</tr>
END IF

Cheers,

Ben.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top