Hello All,
i have a gridview with columns like ItemNo, Title, Price, Size. everything is coming from SQL DB. what i am trying to do is to display a DDL in the gridview so that both the price and Size are diplayed in a DDL format. to explain clearly right now for every itemno, i have different sizes namely 1,2,3,4,5 etc and a different price according to the sizes. for example
itemno title price size
A1001 Red Shoes $15 2
A1001 Red Shoes $20 4
A1001 Red Shoes $25 7 and so on.
as you can see its displaying the title and itemno so many items. i was wondering if there's way to just display itemno and title ( just once ) and their respective prices and sizes in a DDL's. something
like below.
itemNo title price size
A1001 Red Shoes $15 2
$20 4
$25 7
here is the complete code i have so far.
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="GVsearch.aspx.cs" Inherits="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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalDBConnectionString %>"
SelectCommand="SELECT [ItemNumber], [Title], [Price], [SizeName],[Description],[ShortTitle],[ShortDescription] 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:BoundField DataField="ItemNumber" HeaderText="Item" InsertVisible="False"
SortExpression="ItemNumber" HtmlEncode="False" />
<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="Size" SortExpression="SizeName" HtmlEncode="False" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" HtmlEncode="False" />
</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>
</div>
</form>
</
body>
</
html>
--------------------------- CODE BEHIND------------
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;
public partial class GVsearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_OnClick(object sender, EventArgs e)
{
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;
}
}
any ideas or suggestions are highly appreciated.
Thanks once again