473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Data Rendering in ASP.NET Data Controls

Hello All,

Need help in the following:

Assume that a SQL query has 3 columns the data is shown something as:

Content1 Country USA
Content1 Country UK
Content1 Alias MyName
Content2 Country Canada
Content2 Alias OtherName

---keeping in mind the above way of the records, i would like to know how we can display the same on ASP.NET page using any data control in the following way??

CONTENT ALIAS COUNTRY
Content1 MyName USA, UK
Content2 OtherName Canada

Here CONTENT, ALIAS, COUNTRY are the column headers in the data control (can be datagrid etc..), keep in mind ALIAS and COUNTRY are records in the sql query mentioned above
Jul 19 '06 #1
1 3242
Take your input from the Database as a Dataset.
The DataSet.Tables[0] will have a DataTable.
Iterate through this old DataTable

Create a new DataTable. Create DataColumns. Create a new Row. Wherever you have two items seprated by a ',' , you create your own String and stick it in that new column/row.

Keep adding New Rows to new DataTable. Iterate through all the rows in old datatable.

Basically, you take your old DataTable returned from SQL Stored Procedure (or query), modify it to the way you want it , put it in another DataTable. You have to constcurtc the Columns and Rows of the second DataTable manually.

something like this:
private MakeTable(){
// Create a DataTable. DataTable myTable = new DataTable("myTable");
// Create a DataColumn and set various properties.
DataColumn myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.Decimal");
myColumn.AllowDBNull = false;
myColumn.Caption = "Price";
myColumn.ColumnName = "Price";
myColumn.DefaultValue = 25;
// Add the column to the table.
myTable.Columns.Add(myColumn);
// Add 10 rows and set values.
DataRow myRow;
for(int i = 0; i < 10; i++){
myRow = myTable.NewRow(); myRow["Price"] = i + 1;
// Be sure to add the new row to the DataRowCollection.
myTable.Rows.Add(myRow);
}
}

Once you get a DataTable, you can bind it to the DataGrid. Use BoundColumns.
<asp:datagrid id="DataGridInTransit" runat="server" AlternatingItemStyle-BackColor="#999999"
AutoGenerateColumns="False" CssClass="Arial10-Black" ShowHeader=true BorderWidth=0 AllowSorting=True OnSortCommand="SortInTransit" Width="100%" >
<AlternatingItemStyle BackColor="#999999"></AlternatingItemStyle>
<HeaderStyle CssClass="Freezing" BackColor=#FFFFFF ></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="Transaction_ID" SortExpression="Transaction_ID" ItemStyle-CssClass="Arial9-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Trade ID</span>" ></asp:BoundColumn>
<asp:BoundColumn DataField="Year" SortExpression="Year" ItemStyle-CssClass="Arial9-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Yr</span>" ></asp:BoundColumn>
<asp:BoundColumn DataField="Make" SortExpression="Make" ItemStyle-Width="5%" ItemStyle-Wrap=True ItemStyle-CssClass="Arial9-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Make</span>"></asp:BoundColumn>
<asp:BoundColumn DataField="Model" SortExpression="Model" ItemStyle-Width="5%" ItemStyle-Wrap=true ItemStyle-CssClass="Arial9-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Model</span>" ></asp:BoundColumn>
<asp:BoundColumn DataField="Series" ItemStyle-Wrap=True ItemStyle-Width=80 SortExpression="Series" ItemStyle-CssClass="Arial9-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Type/Series</span>" ></asp:BoundColumn>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Condition_URL" DataTextField="Vin" HeaderText="VIN" ></asp:HyperLinkColumn>
<asp:BoundColumn DataField="Est_Delivery_Date" ItemStyle-CssClass="Arial10-Black" HeaderText="Est. Delivery&lt;br&gt;Date"></asp:BoundColumn>
<asp:BoundColumn DataField="turn_time" SortExpression="turn_time" ItemStyle-CssClass="Arial10-Black" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Turn<br>Time</span>"></asp:BoundColumn>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="LIKE_HISTORY_URL" DataTextField="LIKE_HISTORY" HeaderText="<span style='cursor:hand;' class='SortingTableHead'>60-DAYS <BR> HISTORY</span>" ItemStyle-CssClass="Arial11-Black"></asp:HyperLinkColumn>

<asp:BoundColumn DataField="Total_Purchase_Amount" ItemStyle-CssClass="Arial9-Black" SortExpression="Total_Purchase_Amount" DataFormatString="{0:$0,0}" ItemStyle-HorizontalAlign=Right HeaderStyle-HorizontalAlign=Right HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Purchase<br>Amount</span>"></asp:BoundColumn>
<asp:BoundColumn DataField="target_retail_amount" ItemStyle-CssClass="Arial9-Black" SortExpression="target_retail_amount" DataFormatString="{0:$0,0}" ItemStyle-HorizontalAlign=Right HeaderStyle-HorizontalAlign=Right HeaderText="<span style='cursor:hand;' class='SortingTableHead'>Retail<br> Amount</span>"></asp:BoundColumn>
</Columns>
</asp:datagrid>
Jul 19 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
0
by: Alexander Brown | last post by:
Hello, Can anyone suggest a solution to my problem. I have a number of irregularly shaped, overlapping, semi transparent controls. When these controls are resized (which they are, constantly)...
3
by: David Whitney | last post by:
All: I have a control that renders a table. As the table is rendered, each row in the table is constructed by creating a run-time (dynamic) object that is derived from an HtmlTableRow. The row...
2
by: axis | last post by:
I have two custom controls on a page that work on the same object that needs some prepping when first loaded. Currently I just load them in both controls individually, essentially doing the same...
1
by: sonic | last post by:
I generate a button link control in following Manner. Button b = new Button(); b.Click = MyEventHandler(...); If i add this button to current control with: this.Controls.Add( b ); it will...
5
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever....
5
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
6
by: Ken Fine | last post by:
I'm using SQLDataSource, which generates some kind of dataset, and then I attach that datasource to various data display controls such as DataList and repeater which loop through to the end of the...
1
by: lak | last post by:
got a question in vb.net I have a form that render controls on panels for several pages.There are 10 controls per page. suppose I have a control say class on 4 th page that i need to get more...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.