Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
how to insert,update and delete an images using file upload control in gridview?
Posted 15-Jan-13 18:38pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>
Please Select A Brand To See its Laptop Models</h2>
<table class="style20">
<tr>
<td class="style16">
<asp:Label ID="BrandNameLabel" runat="server" Text="Brand Name"></asp:Label>
</td>
<td class="style17">
<asp:DropDownList ID="BrandNameDropDownList" runat="server" AutoPostBack="True"
Height="22px" Width="155px"
onselectedindexchanged="BrandNameDropDownList_SelectedIndexChanged">
<asp:ListItem Text="Select something" Value="-1" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style16">
<asp:Label ID="ProductNameLabel" runat="server" Text="Product Name"></asp:Label>
</td>
<td class="style17">
<asp:DropDownList ID="ProductNameDropDownList" runat="server" Width="157px"
AutoPostBack="True"
ondatabinding="ProductNameDropDownList_DataBinding"
ontextchanged="ProductNameDropDownList_TextChanged">
<asp:ListItem Text="Select something" Value="-1" />
</asp:DropDownList>
</td>
</tr>
</table>
<asp:GridView ID="GridView" runat="server" BackColor="White"
BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"
GridLines="Horizontal" AutoGenerateColumns="False" AllowPaging="True"
PageSize="1" Width="819px" ForeColor="#003366"
AutoGenerateEditButton="True" onrowediting="GridView_RowEditing">
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Specification">
<ItemTemplate>
<asp:Label ID="Specificationlabel" runat="server" Text='<% # Eval("Specification") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="PriceLabel" runat="server" Text='<% # Eval("Price") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Instock">
<ItemTemplate>
<asp:Label ID="InstockLabel" runat="server" Text='<% # Eval("Instock") %>' />
</ItemTemplate>
</asp:TemplateField>
 
</Columns>
</asp:GridView>
<br />
<br />
<br />
<br />
</asp:Content>
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class BrandSearchLaptop : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectioninfo"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("Select * from LaptopBrandTable", con);
SqlDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
BrandNameDropDownList.Items.Add(dr1["BrandName"].ToString());
}
con.Close();
}
}
protected void BrandNameDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
ProductNameDropDownList.Items.Clear();
String A=BrandNameDropDownList.SelectedValue;
string B = ProductNameDropDownList.SelectedValue;
if (B == "No Product Exists..")
{
GridView.DataSource = null;
GridView.DataBind();
}
else
{
con.Open();
SqlCommand cmd2 = new SqlCommand("Select * from LaptopTable Where BrandName='" + A + "'", con);
SqlDataReader dr2 = cmd2.ExecuteReader();
ProductNameDropDownList.Items.Add("Please Select");
if (dr2.HasRows == true)
{
while (dr2.Read())
//Names collection is a combo box.
ProductNameDropDownList.Items.Add(dr2["ProductName"].ToString());
}
else
{
ProductNameDropDownList.Items.Clear();
ProductNameDropDownList.Items.Add("No Product Exists..");
GridView.DataSource = null;
GridView.DataBind();
//PriceTextBox.Text = string.Empty;
}
con.Close();
}
 
}
protected void ProductNameDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
void BindGrid()
{
SqlDataAdapter da = new SqlDataAdapter("select * from LaptopTable where ProductName='" + ProductNameDropDownList.SelectedItem + "'and BrandName='" + BrandNameDropDownList.SelectedItem + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView.DataSource = ds;
GridView.DataBind();
}
protected void ProductNameDropDownList_DataBound(object sender, EventArgs e)
{
}
protected void ProductNameDropDownList_DataBinding(object sender, EventArgs e)
{
}
protected void ProductNameDropDownList_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView.EditIndex = e.NewEditIndex;
BindGrid();
}
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 Andreas Gieriet 100
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100