VB.NET - Concatenating fields in a grid

Hi,

I need to combine three fields into one column.

I made a grid in VB.NET that displays data from 3 fields in my database.  Here is a screenshot of how it comes out:
http://danallen.com/pics/grid.JPG


CODE PRODUCING THE GRID
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource_ThinkVTCalendarItems" DataKeyNames="ID,UserID,ModuleId" CellPadding="4" CellSpacing="1" EnableViewState="False">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" Visible="False" />
<asp:BoundField DataField="ModuleId" HeaderText="ModuleId" SortExpression="ModuleId" Visible="False" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" Visible="False" />
<asp:HyperLinkField DataTextField="calendarLINK" DataNavigateUrlFields="calendarURL" HeaderText="Event"  />
<asp:BoundField DataField="calendarLOC" HeaderText="Location" SortExpression="calendarLOC"  />
<asp:BoundField DataField="calendarDisplayDATE" HeaderText="Date" SortExpression="calendarDisplayDATE"  />
</Columns>


PROBLEM:
I need to make this grid have one column, filled with the three fields from grid I have now.  The column of values should come out like this:

6th Annual Workplace Safety Conference - Dusquene February 13, 2008
Forklift Operator Safety Training - White Plains February 15, 2008
etc...

Important:  The event name, before the dash, needs to be a link.  The dash and the location are plain text.  The dates need to be bold.  The full string needs to be in one column, not 3.

QUESTION
How do I change the code above to get the single column with the combined/concatenated string I need?

As always, any assistance in answering this question will be appreciated immensely.

Best regards,
Danimal
LVL 1
DanimalAsked:
Who is Participating?
 
NazoUKConnect With a Mentor Commented:
Given your criteria above I think this should work:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource_ThinkVTCalendarItems" DataKeyNames="ID,UserID,ModuleId" CellPadding="4" CellSpacing="1" EnableViewState="False">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" Visible="False" />
<asp:BoundField DataField="ModuleId" HeaderText="ModuleId" SortExpression="ModuleId" Visible="False" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" Visible="False" />
<asp:TemplateField HeaderText="Event">
    <ItemTemplate>
        <a href='<%#Eval("calendarURL") %>'><%#Eval("calendarLINK") %></a>
         - <%#Eval("calendarLOC") %> <b><%#Eval("calendarDisplayDATE") %></b>
    </ItemTemplate>
</asp:TemplateField>
</Columns>
0
 
QPRCommented:
Not sure which 3 columns we are dealing with but....
turn column 1 into a template field and remove the other 2.
Switch to code view and build your column like....

eval("column1") & "-" & eval("column") etc etc
Another way (but ugly) would be to do it in your select (if the datasource is a query)
select column1 + '<strong>' + column2 + '- </strong>' as SomeColumnName
0
 
DanimalAuthor Commented:
QPR, thank you for answering quickly.

I understand how to do this with SQL, but I would rather do it the first way you suggested.  Unfortunately, I am still pretty new with .NET, so my confusion is very basic.

The columns I am dealing with are
calendarLINK + calendarURL
calendarLOC
calendarDisplayDATE

I am working only in code view.
How do I get the three fields to evaluate the way you are saying in one column? In classic ASP, it would look something like this:

Foreach returned record:
<a href="<%=calendarURL%>">calendarLINK</a>-<%=calendarLOC%> <b><%=calendarDisplayDATE%></b>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
DanimalAuthor Commented:
NazoUK,

Thank you!  That code snippet looks exactly like what I need.

This probably gets into something slightly broader, but when I ran the code you provided, I got this error:
error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types. ---> System.Web.HttpCompileException
0
 
QPRCommented:
remove the three bound columns from your code and instead add a template column

<asp:templatefield>
<itemtemplate>
<a href=<%# eval("calendarURL") %> calendarLink</a>-<%#eval("calendarLOC")%><b><%#eval("calendarDisplayDATE")%></b>
</itemtemplate>
</asp:templatefield>
0
 
NazoUKCommented:
Somewhere in your code-behind you have a sub routine that is trying to handle an event for a control that it can't find. Look for a sub routine that has handles after it and make sure there is a control that matches the name.

Eg. Sub Button1_click(sender as object, e as eventargs) handles button1.click

in this case there should be a button called button1 on the page.
0
 
DanimalAuthor Commented:
Thank you very much!
0
 
DanimalAuthor Commented:
NazoUK, I made a mistake applying the code you provided.  When I tried again, it worked.
0
All Courses

From novice to tech pro — start learning today.