how to pull several columns info from db then display them as one column in datagrid?

I have difficulty to gether several columns info from db to display them as one column in datagrid. say I have a table which has columns: "name", "street", "address", "city", "state", "zip", "status",

Ex: I want to pull "street address", "city", "State", and "zip" from that table then diaplay them as one column "Address" in the datagrid so that the datagrid will only have 3 columns to display --"Name", "Address" and "Status". How do I do it with the format of
street address
city, state zip
for "Address" column?
thanks
0
calliawang
9/29/2003 3:27:44 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
524 Views

Similar Articles

[PageSpeed] 8

use template columns..


<asp:TemplateColumn HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "street") %>' Runat=server />,
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "city") %>' Runat=server />,
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "state") %>' Runat=server />
</ItemTemplate>

</asp:TemplateColumn>

HTH
***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
9/29/2003 3:35:43 PM
thanks for helping though I do still have problem.  after using TemplateColumn, for Address column, only zip code is being displayed(street adress, city, state info are missing) and employer name, address, status column are being repeated twice that is I have 6 columns instead of 3 columns displayed in the datagrid.

they are in the order of
employerName street status employerName street status
what's the problem?
========here is my code===============================================
<asp:datagrid runat="server" id="ID_of_DataGrid"
HeaderStyle-Font-Bold="True"
cellspacing="10" cellpadding="10" align ="center"
Wrap ="true"
BorderColor="black"
ShowFooter="false"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BorderColor = "brown"
HeaderStyle-BackColor= "palegoldenrod">
<Columns>

<asp:BoundColumn DataField="employer_name" HeaderText="Employer Name" readonly ="true" />


<asp:TemplateColumn HeaderText="Address">

<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "street") %>' Runat=server />,
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "city") %>' Runat=server />,
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "state") %>' Runat=server />
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "zip") %>' Runat=server />,
</ItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn DataField="status" HeaderText="Status" readonly ="true" />
</Columns>
</asp:DataGrid>
0
calliawang
9/29/2003 6:37:23 PM
You can set AutoGenerateColumns = false

HTH
Sushila Bowalekar Patel
Visual ASP/ASP.NET MVP
http://weblogs.asp.net/sushilasb
0
SushilaSB
9/29/2003 6:50:31 PM
Oh, yes, I just find out to set AutoGenerateColumns="false" so one of my problem has solved but still one more.

I dont understand why street, city and state info are missing. I want to combine those fields together and to display them as one column (Address) in datagrid. They should be displayed in
street
City, State zip
format.
I do have stree, city, state, zip info stored in my database, why using TemplateColumn wouldn't combine them together? Is anything wrong within my code? I don't see it. Could someone point it out for me? Thanks.
0
calliawang
9/29/2003 7:03:20 PM
Try


<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "street") %>' Runat=server />,

<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "city") %>' Runat=server />,
<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "state") %>' Runat=server />

<asp:Label ID="lblOrderId" Text='<%# DataBinder.Eval(Container.DataItem, "zip") %>' Runat=server />,
</ItemTemplate>

Sushila Bowalekar Patel
Visual ASP/ASP.NET MVP
http://weblogs.asp.net/sushilasb
0
SushilaSB
9/29/2003 7:16:28 PM
THANKS again for helping.  No, it would not work if I use <asp:Label ID="lblOrderId".../>, it will give me an error saying that a control is already exist.

but I can get it work --sort of work by doing this
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "street") %>,
<%# DataBinder.Eval(Container.DataItem, "city") %>,
<%# DataBinder.Eval(Container.DataItem, "state") %>
<%# DataBinder.Eval(Container.DataItem, "zip") %>
</ItemTemplate>
this will display street, city, state, and zip as one column in my datagrid but it is not in the right format.--- I want to format it as what we write an address in real world that is to display it in two lines--one for street address, second line to have ciry, state and zip
like this:
street address
city, state zip
I still couldn't figure it out how to manage this yet. Any idea? Thanks
0
calliawang
9/29/2003 7:47:51 PM
try this :


<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "street") %> <br>
<%# DataBinder.Eval(Container.DataItem, "city") %>,
<%# DataBinder.Eval(Container.DataItem, "state") %>
<%# DataBinder.Eval(Container.DataItem, "zip") %>
</ItemTemplate>

***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
9/29/2003 8:30:49 PM
Sorry  the id's shud be with different names i just copied and pasted it as per ur code and missed to change the id's

try

<ItemTemplate>
<asp:Label ID="lbl1" Text='<%# DataBinder.Eval(Container.DataItem, "street") %>' Runat=server />, <br>
<asp:Label ID="lbl2" Text='<%# DataBinder.Eval(Container.DataItem, "city") %>' Runat=server />,
<asp:Label ID="lbl3" Text='<%# DataBinder.Eval(Container.DataItem, "state") %>' Runat=server />
<asp:Label ID="lbl4" Text='<%# DataBinder.Eval(Container.DataItem, "zip") %>' Runat=server />,
</ItemTemplate>

You can do this in case you want label control to be used
or else
as suggested by ndinakar

Sushila Bowalekar Patel
Visual ASP/ASP.NET MVP
http://weblogs.asp.net/sushilasb
0
SushilaSB
9/30/2003 12:38:53 AM
thank you all for helping.  It works now.  Great.  thanks again.
0
calliawang
9/30/2003 5:20:56 PM
Reply:

Similar Artilces:

two db table column, one datagrid column
Dear all, I have a db table which have two column, first name and last name. Can I show them in one datagrid column? Thanks Yes you may. Through the usage of the TemplateColumn, yes. An example of this: <code> <asp:DataGrid runat="server" ID="dgSomeGrid">     <Columns>         <asp:TemplateColumn>             <ItemTemplate>                 <%# DataBinder.Eval(Container.DataSource, "LastName") %&g...

Display Multiple Columns into One Column
My first ASP.NET/SQL project. I'm creating an Asset Management DB. I wish to view the Asset number, the full name of the user it's assigned to and the Make and Model of each record in the DB. However assets are split into different categories e.g. monitors, PCs, Preinters etc. and they are all in different tables. The SQL below displays the asset number, Name of person assigned and the model of the asset. SELECT Hardware.AssetNo, [User].FullName, MonitorModel.Model, PCModel.Model AS Expr1, PrinterModel.Model AS Expr2 FROM Hardware INNER JOIN [User] ON Hardware.UserID = [User].User...

datagrid column header bring up pop window which show info pulled from a db table
in my last post, I forget to say that the column header is from a datagrid. I have set the AutoGenerateColumns="false". What I want to do is to be able to click on one column header, it will bring up a small popup window to display some info which stored in a database table. Could someone lead me to some useful articles/links where talking about how to deal with this situation or someone knows how to do it exactly. I have been searching the web, and haven't found anything really helpful yet. Thanks....

How to display the sum of a column at the footor of the datagrid column
HI, Any idea how I can display the Sum of any column at the Footor of that Column. HighOnCodingWanna get high! Hi, Take a look @ Displaying Column Summary Information in the Footer HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates....

Only one table column in n-columns presentation style
Hi all, I think it�s better to explain our problem with an example. Any idea to do this data (2 records): ID: 1 DATE: 19/01/2000 OBS: 11111111111 22222222222 333333 aaaaaaaa line444ae q qwe qweqee ID: 2 DATE: 19/01/2000 OBS: ad asdasda as fffffffffff hhhhhhh mmmmmmmmmPPPPPPPPPP ooooo on one DataObject (something) like: ************ ID: 1 DATE: 19/01/2000 OBS: 111111111111 aaaaaaaa 444ae 22222222222 q qwe qweqee 333333 ************ ID: 2 DATE: 19/01/2000 OBS: ad asdasda as PPPPPPPPPP ...

Display Key columns and all columns for tables in one diagram
In Tools->Display Option-> Object View ->Table, you could choose to display only key columns, PK columns, top X columns or all columns for tables. But it applies to the whole diagram. I wonder whether we could do it on table level, say to display all columns for fact table but just PK columns for dimension tables so we could squeeze one subject area in one page. Thx, Richard Mei BMO Financial Groups Manually drag up the bottom of the table outline to show just the columns you want. -- Mike Nicewarner [TeamSybase] http://www.datamodel.org mike@nospam!datamodel...

How to display column total of numeric columns in the datagrid footer
I able to connect Datagrid control to ADO.Net for pulling data. But I can not able to display total of a numeric field column in the Datagrid footer. Is it possible? How? Please tell me any one. Hi, please read up Displaying Column Summary Information in the Footer and HOW TO: Create a Summary Row for a DataGrid in ASP.NETHope this helps..Alvin ChooiMicrosoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com...

Can you have a hyperlink column and and edit column in one datagrid?
Hi All, Is it possible to have a datagrid that has a hyperlink column so the data related to that particular row is viewable on another page and also have a edit, cancel, update column to edit data in that grid. As i am unable to get my edit commands to work and i was wondering whether i cannot do this as i have a hyperlink column. Also does anyone have any suggestions Thanks  yes you can have as many hyperlink columns you want. infact edit,insert update delete are also hyperlink button in one columns with their respective command arguments and source values Thanks   &...

Dividing one column to 4 columns in the Repeater control
Hi Folks, The following is my Repeater-Control code that providing a list of 20 companies names. I'm getting all of the data in one long column and I would like to divide this one column to 4 columns. Is it possible? how can I do it in my code: <asp:Repeater ID="catlist" runat="server"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> ...

Copy Data From One Datagrid Column To Another Column
Hi all, I am trying to copy data from one column in a datagrid to another column in the same datagrid. I am using buttons to do this, not the edit, update, cancel datagrid buttons. This is what I have been trying but with no luck :int RowCount;RowCount = 1;string DataValue;//while (RowCount < DataGrid1.Items.Count)//{// DataGrid1.SelectedIndex = RowCount;// DataGrid1.SelectedIndex = RowCount;// DataValue = DataGrid1.SelectedItem.Cells[4].Text;// DataGrid1.SelectedItem.Cells[3].Text = DataValue;} Help appreciated thanks. Try this <%@ Page Language="C#" %&...

display the sum of two datagrid columns into third column
hi... there..     i have a datagrid with columns named Price ,Quantity and total. now in the total column i  wanna display the prices which comes by multiplyiing the price and quantity (like  total=Price * quantity). I'm workin in asp.net +vb.net.                     may i knw hw can i do this.. plz write the code.. thanks.         Hi, do like this..suppose u have,        string ProductPrice = ...

column header to span two columns in a datagrid display
Is it possible for a column header to span two columns? If so how would this be done? Thanks In the ItemDataBound (or ItemCreated) check if Item is of type Header and if so - define the colspan property of the Cell object which you want to define the Colspan for and delete the next Cell from hte DataGridItem CheersBug [MCSD] Is it possible to span header column in design view only. using some kind of CSS. I'm using ASP,NET 3.5 and GridView...

Making hyperlink on one column in datagrid from values in other column
Dear friends,  I have columns in database: id, homepage (stores url of persons hompage), name. I want to display in datagrid in such a way that: Only name as hyperlink (hyperlink value to be retrieved from id value, so that direct link will not be available) will appear in datagrid. So, that when user will click on hyperlinked email, it should get redirect to homepage url i.e.<a href=redirect.aspx?id=1>John></a> Only john should appear in gridview and will be redirected to is homepage say www.xyz.com/john   Thanks If u mean, how to place the I...

Displaying image in a column of a datagrid control
Hi Experts, How can i display an image in a column of a datagrid control? On clicking that image i want to redirect to another screen based on the row selected. Also how should i open an popup screen by clicking the hyperlink column of a datagrid control. It is similar to a message board forum.(viewing all the messages posted with details) Thanks in advance. Hi, you can take a look at this article. There are many others around when you google for it. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons....

Web resources about - how to pull several columns info from db then display them as one column in datagrid? - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 1/19/2016 12:57:10 PM