Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to display this in a gridview or table

Posted on 2008-10-06
8
Medium Priority
?
266 Views
Last Modified: 2013-11-26
Hello All,
I am trying to display my search results in Gridview. it works but the problem is i want it to display in this format
itemNo            desc                size          price
AZ100          White Shoes        8            $15
                                                  9            $20
                                                  10          $22
                                                 11-13     $30
AZ101         Black Shoes          8            $15
                                                 12          $30
but right now it display like this
AZ100       White Shoes      8               $15
AZ100       White Shoes      9              $20
AZ100        White Shoes     10          $22
AZ100       White Shoes     11-13       $30

AZ101        Black Shoes        8       $15
AZ101        Black Shoes        12    $30

how can i display in first way. can some one please help me out. i am stuck
i am posting my complete code
Thanks a lot i really appreciate it.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GVsearch.aspx.cs" Inherits="MySite.GVsearch" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>SQL and GV seach page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox id="txtSearch" runat="server" />
 
<asp:Button id="btnSearch" runat="server"
    Text    = "Search"
    OnClick = "btnSearch_OnClick" />
    <br />
        <asp:Panel ID="SearchPanel" runat="server" Visible="false">
       
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MySiteDBConnectionString %>"
            SelectCommand="SELECT [ItemNumber], [Title], [Price], [SizeName],[Description],[ShortTitle],[ShortDescription],[TitleImage],[ThumbnailImage] FROM [SearchTable] WHERE (([Title] LIKE '%' + replace(@Title, ' ', '%') + '%') OR ([ShortDescription] LIKE '%' + replace(@ShortDescription, ' ', '%') + '%') OR ([ShortTitle] LIKE '%' + replace(@ShortTitle, ' ', '%') + '%') OR ([Description] LIKE '%' + replace(@Description, ' ', '%') + '%') OR ([ItemNumber] LIKE '%' + replace(@ItemNumber, ' ', '%') + '%') OR ([SizeName] LIKE '%' + replace(@SizeName, ' ', '%') + '%'))" OnSelecting="SqlDataSource1_Selecting" >
            <SelectParameters>
                <asp:Parameter  Name="Title"  Type="String" />
                <asp:Parameter  Name="ShortDescription" Type="String" />
                <asp:Parameter  Name="ShortTitle" Type="String" />
                <asp:Parameter  Name="Description" Type="String" />
                <asp:Parameter  Name="ItemNumber"  Type="String" />
                <asp:Parameter  Name="SizeName" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    <br />
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="ItemNumber" DataSourceID="SqlDataSource1" ForeColor="#333333"
            GridLines="None" AllowSorting="True">
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="Item" InsertVisible="False" SortExpression="ItemNumber">
                   <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("ItemNumber") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Title" HeaderText="Product Name" SortExpression="Title" HtmlEncode="False" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"  DataFormatString="{0:c}" HtmlEncode="False" />
                <asp:BoundField DataField="SizeName" HeaderText="Sizes" SortExpression=SizeName HtmlEncode="False" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" HtmlEncode="False" />
                <asp:TemplateField HeaderText="Image Preview">
                <ItemTemplate>
                <asp:Image ID="ImgThumb"  runat="server" ImageUrl='<%# Bind("ThumbnailImage","images/products/S/{0}") %>'   />
                </ItemTemplate>
                  </asp:TemplateField>
</Columns>
            <RowStyle BackColor="#E3EAEB" />
            <EditRowStyle BackColor="#7C6F57" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        
 </asp:Panel>   
    
    </div>
    
    </form>
</body>
</html>
-------------------------CODE BEHIND---------------------------------
namespace MySite{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using WoodenSoldier.catalog;
 
    public partial class GVsearch : MySitePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void btnSearch_OnClick(object sender, EventArgs e)
        {
            SearchPanel.Visible = true;
            GridView1.DataBind();
        }
 
 
 
        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.Parameters["@Title"].Value = txtSearch.Text;
            e.Command.Parameters["@ShortDescription"].Value = txtSearch.Text;
            e.Command.Parameters["@ShortTitle"].Value = txtSearch.Text;
            e.Command.Parameters["@Description"].Value = txtSearch.Text;
            e.Command.Parameters["@ItemNumber"].Value = txtSearch.Text;
            e.Command.Parameters["@SizeName"].Value = txtSearch.Text;
           
        }
 
        
 
    }
}

Open in new window

0
Comment
Question by:niceoneishere
[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
  • 5
  • 3
8 Comments
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 2000 total points
ID: 22651431
MS GridView doesnt support merging cells. What could be done behind the scenes, is this

1) check the item nu,mber the current record in datatable (start from send record).
2) If its the same as the previous, then replace it with null value

same for description. if you rae showing grid lines, then they will be visible for every cell, no matter if it contains null value.

Goran
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22653694
Hello Sir,
is it possible that you can post an example or an reference like an tutorial or an article for what you have suggested. i really appreciate it.

Thanks a lot .
0
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 2000 total points
ID: 22653872
well, this is some to get you going

for (int i = 1; i < dt.Rows.Count; i++) // we start from 1, we want to skip first record
{
    if (dt.Rows[i]["ItemNo"].ToString() == dt.rows[i - 1]["ItemNo"].ToString()
    {
        dt.Rows[i]["ItemNo"] = "";
    }
    if (dt.Rows[i]["desc"].ToString() == dt.rows[i - 1]["desc"].ToString()
    {
        dt.Rows[i]["desc"] = "";
    }
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:niceoneishere
ID: 22654249
Hello Sir,
Thanks for the tip but one question where would i use this , is it RowDataBound of the GridView.
i appreciate it sir
Thanks
0
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 2000 total points
ID: 22654406
This should be done after you have populated DataTable, and before you have binded GridView to DataTable.
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22668160
Hello Sir,
Thanks a lot for your help, but i was wondering if i want to display the all the sizes for a particular ItemNo in DropDownList, inside the GridView. is that possible sir, can you please advice me or  give an example.

once again i really appreciate your patience and help. i am still in the learning process.
Thanks
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 22668800
Hello Sir,
here is my code with the Drop Down List in the Grid. but my problem is instead of display only the sizes for a particular Item No. it display all the sizes available in Database. what i mean say for example if itemNo A1001 comes in size 8,9,10,12 i want the Drop Down List to display only those sizes but right now it displays all sizes from 6, 7,8,9,10,11,12,13,14 etc.
can you please advice how to achieve what i am looking for sir. i am attaching my code.
Thanks once again i appreciate it.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DDLandGV.aspx.cs" Inherits="Menu_DDLandGV" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalDBConnectionString %>" 
        SelectCommand="SELECT DISTINCT [ItemNumber], [Title], [Price], [Description] FROM [SearchTable]"></asp:SqlDataSource>
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" CellPadding="4"
            DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:BoundField DataField="ItemNumber" HeaderText="ItemNumber" SortExpression="ItemNumber" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" DataFormatString="{0:c}" HtmlEncode="False" />
                <asp:TemplateField HeaderText="Available Sizes">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                     DataSourceID="SqlDS2" DataTextField="SizeName"
                      DataValueField="ItemNumber" SelectedValue='<%# Bind("ItemNumber") %>'>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDS2" runat="server" ConnectionString="<%$ ConnectionStrings:LocalDBConnectionString %>" 
                    SelectCommand="SELECT [ItemNumber], [SizeName] FROM [SearchTable]" >
                    </asp:SqlDataSource> 
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 1

Accepted Solution

by:
niceoneishere earned 0 total points
ID: 22687083
Hello Sir,
i figured it out , i added a control parameter to SqlDS2 and it works like i charm. thanks a lot for your help in this regard. i have awarded you the points.
Thanks one again
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

661 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