?
Solved

Display two records in one row of datagrid

Posted on 2004-08-26
14
Medium Priority
?
321 Views
Last Modified: 2008-01-09
hi
    i am developing an shopping cart web site and i am facing a typical problem,i want to show 2 records side by side in order to get rid of the scrolling to view the product. i and displaying the products lists as one product each row but now is there any way i can show two records side by side using datagrid as i am using datagrid following is the code to display the one record per row

                  <asp:Panel id="pnlShowCart" runat="server">
                        <h1>View Cart</h1>
                        <asp:DataGrid id="dgCart" runat="server" AutoGenerateColumns="false" GridLines="None" CellPadding="3" Width="100%"
                                    DataKeyField="CartID" OnCancelCommand="dgCart_Cancel" OnDeleteCommand="dgCart_Delete" OnEditCommand="dgCart_Edit" OnUpdateCommand="dgCart_Update">
                              <HeaderStyle Font-Name="arial" BackColor="#003366" ForeColor="#FFFFFF" Font-Bold="true" Font-Size="10" />
                              <ItemStyle Font-Name="arial" Font-Size="10" />
                              <Columns>
                                    <asp:EditCommandColumn EditText="Change Quantity" CancelText="Cancel" UpdateText="Update" />
                                    <asp:ButtonColumn ButtonType="LinkButton" CommandName="Delete" Text="Remove" />
                                    <asp:BoundColumn DataField="Item" HeaderText="Product Name" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="Quantity">
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "Quantity") %>
                                          </ItemTemplate>
                                          <EditItemTemplate>
                                                <asp:TextBox id="txtQuantity" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' runat="server" Width="50" />
                                          </EditItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn DataField="Cost" HeaderText="Cost" ReadOnly="true" />
                              </Columns>
                        </asp:DataGrid>
                        <p align="right"><strong>Total: <asp:Label id="lblTotal" runat="server" /></strong></p>
                        <p align="right"><asp:LinkButton id="lbContinue" Text="Continue Shopping" runat="server" OnClick="ContinueShopping" />
                        | <asp:LinkButton id="lbCheckOut" Text="Checkout" runat="server" OnClick="CheckOut" /></p>
                  </asp:Panel>

plz tell me how to change this code to redo this code to show 2 records per row side by side.plz its urgent

Vikram Lashkari
0
Comment
Question by:vikram_lashkari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
14 Comments
 
LVL 11

Expert Comment

by:sachiek
ID: 11900910
You mean nested records?
  I guess you are saying about like the sample shown in this below grid.
  Check and let me know.

  http://www.denisbauer.com/ASPNETControls/HierarGridDemo.aspx
 
  I guess this one will help you out.

Cheers!
Sachi
0
 

Author Comment

by:vikram_lashkari
ID: 11901065
hi Sachiek,
     I donot need  HierarGrid ,but let me explain what i need,
    i need to diplays 2 records in one row just in the example which u have linked me,the Record of the Title ID :PC1035 is displayed in one row and the next Title ID :PS1372 is displayed in the Second row, i want to display these records side by side means after the Pulication Field of the First Record the Next record should dispayed and after these tow records are displayed the third record and foruth has to be displayed in next row after that fith and sixth record has to be displayed in next row.
 plz help me
0
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 11901829
not sure you will be able to do using a datagrid, beacause the data grid outputs a html table. I suppose you could use javascript to alter the tables layout after the page has been sent to the browsers.

You probally hould use the DataList Control as this has RepeatColumns,RepeatDirection and RepeatLayout for controling this kind of thing.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:sachiek
ID: 11902039
Common man...consider some better design. That should help you better in long term.
If you want to leverage the use of .net , surely you need to consider re-design for your requirement.

Cheers!
Sachi
0
 
LVL 11

Expert Comment

by:sachiek
ID: 11902046
http://codeproject.com/cs/database/Vertical_rows_in_Datagrid.asp

Anyway here is one other sample which might help you. This is displaying colum's vertically. I think this is most closer one for your requirement.

Best regards,
Sachi
0
 
LVL 11

Expert Comment

by:sachiek
ID: 11902080
Further drilling i could find one more example.
 
http://www.codeproject.com/aspnet/Datatable.asp

Hope this will help you a lot too.

Cheers!
Sachi
0
 

Author Comment

by:vikram_lashkari
ID: 11902139
hi SACHIEK,
      i think datagrid will not work,how about using repeater,can u just give me a sample code for the repeater to display more than one recored per row, i will be thanful to u and my problem will also solve

plz
0
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 11902463
I'm sure I mentioned the DataList. The DataList Control does what you need out of the box,

http://www.csharpfriends.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datalist/doc_datalist.aspx
0
 

Author Comment

by:vikram_lashkari
ID: 11902555
hi friend AdrianJMartin

   i think the i get my solution but the link which u had send me i am able to view the demo but i am not able to view the source as this is the link and it gives the following error from my computer plz if u can open that source then plz copy and paster for me,i think this is the solution of my problem.

http://www.csharpfriends.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/DataList/DataList2.src

VB\DataList2.aspx  

C# Source:  CS\DataList2.aspx    
VB Source:  VB\DataList2.aspx    
JScript Source:  JS\DataList2.aspx    

Source Viewer Error: cannot show this file

Either the file does not exist, or your configuration settings for the source viewer do not allow files in this directory to be viewed. To edit the configuration settings, see the web.config file at the root of the quickstart directory. Change the <sourceview> setting to point at the root directory of the quickstart. All files under this directory will be accessible to the source viewer.

<configuration>
  <system.web>
    <sourceview>
      <add key="root" value="c:\Program Files\Microsoft.Net\FrameworkSDK\Samples\Quickstart" />
    </sourceview>
  </system.web>
</configuration>

0
 
LVL 5

Accepted Solution

by:
AdrianJMartin earned 1500 total points
ID: 11902706
oops csharpfriends have not remapped some of the links.. :-(

gotdotnet have got it right though :-)
http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datalist/doc_datalist.aspx


you mau already have the code if you have installed the DotNet Framework SDK:
On my machine its @

C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\QuickStart\aspplus\samples\webforms\ctrlref\webctrl\datalist


0
 

Author Comment

by:vikram_lashkari
ID: 11903342
hi Adrian
   i will implement it today if it works out properly with the database records then i will report u back,

   thanx,
0
 

Author Comment

by:vikram_lashkari
ID: 11940082
hi adrian,

    It is working but one problem with the DataList is that I cannot Do the Paging with  the Datagrid,so Plz if u solve my this problem with datalist or If can u tell me that is there any property like RepeatColumn in DataGrid also just like DataList then my all problem will be solved as if i change to the DataList from the Datagrid i won't be getting  the advantage of the Paging.

   so Please help he out.But i think your solution is Perfect when i have to implement on Datalist
0
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 11940139
Somebody please correct me if i'm wrong but. When you use 'paging' the all the data bound data is persisted via the viewstate. Which can lead to large http roundtrips. If you are OK with the size of the roudn trips then you could just roll you own paging using javascript to set the css style of the 'hidden' items to "display:none" and the visible ones to "display: inline" or "display:block".

Or persist your data in the application or cache collection and create a dataview object and bind the datalist/grid to the dataview, - which has the advantage of much smaller postback round trips. Then have buttons which manipulate the filter expression for the view, ie filter on the modulos of the rowcount to achieve paging( you may need to create some dummy rows to achieve this.)
0
 

Author Comment

by:vikram_lashkari
ID: 11940169
hi Adrian,
       I just need ur help to do paging like 1,2,3,4,5 that is i need the number of pages has to be displayed for my record in datalist. Just for example when u do search in google.com u will find that 1 to 10 pages linked are displayed for the results found and not the remaining pages u have next button and when u press the next button u will see the remaining page no, same i have to do with either datalist or datagrid ,just give me like or code here or at my email:vikram_lashkari@yahoo.com as ,the answer to my question related to this topic is already given by u thank. but plz solve my this problem.Thanx AdrianJMartin.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question