470,614 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

controlling databound ASP

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.
Aug 15 '07 #1
6 1310
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.
"Ben." <Be*@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
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.

Aug 15 '07 #2
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.
Aug 15 '07 #3
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
"Ben." <Be*@discussions.microsoft.comwrote in message
news:DD**********************************@microsof t.com...
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.

Aug 15 '07 #4
The easiest way is to have your sql statement take care of it
Select * from (table) where (fieldname) is not null

David Wier
http://iWritePro.com
http://aspnet101.com

"Ben." <Be*@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
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.

Aug 15 '07 #5
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."
"David Wier" <da*******@davidwier.nospam.comwrote in message
news:Oo**************@TK2MSFTNGP03.phx.gbl...
The easiest way is to have your sql statement take care of it
Select * from (table) where (fieldname) is not null

David Wier
http://iWritePro.com
http://aspnet101.com

"Ben." <Be*@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
>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.


Aug 15 '07 #6
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.

"Mike" wrote:
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."
"David Wier" <da*******@davidwier.nospam.comwrote in message
news:Oo**************@TK2MSFTNGP03.phx.gbl...
The easiest way is to have your sql statement take care of it
Select * from (table) where (fieldname) is not null

David Wier
http://iWritePro.com
http://aspnet101.com

"Ben." <Be*@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
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.


Aug 15 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Andrey Mosienko | last post: by
1 post views Thread by Patrick Demets | last post: by
reply views Thread by John Smith | last post: by
reply views Thread by Ken Varn | last post: by
8 posts views Thread by GaryDean | last post: by
3 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.