using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.IO;
using System.Collections;
using System.Text;
namespace WebApplication7
{
public partial class viewad1 : System.Web.UI.Page
{
public string adv;
public string usr;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropDownList();
FillDropDownList1();
}
}
protected void FillDropDownList()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sampledbConnectionString"].ConnectionString);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select * FROM category", conn);
myda.Fill(ds);
conn.Close();
catddlist.DataSource = ds;
catddlist.DataTextField = "category_name";
catddlist.DataValueField = "category_id";
catddlist.DataBind();
catddlist.Items.Insert(0, new ListItem("Select", "0"));
subcatlist.Items.Insert(0, new ListItem("Select", "0"));
}
protected void FillDropDownList1()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sampledbConnectionString"].ConnectionString);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select * FROM places", conn);
myda.Fill(ds);
conn.Close();
citylist.DataSource = ds;
citylist.DataTextField = "cityname";
citylist.DataValueField = "city";
citylist.DataBind();
citylist.Items.Insert(0, new ListItem("Select", "0"));
}
//Double click on Company`s DropDown.;
protected void catddlist_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sampledbConnectionString"].ConnectionString);
conn.Open();
int catid = Convert.ToInt32(catddlist.SelectedValue);
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select subcategory_id,subcategoryname FROM subcategory where category_id=" + catid, conn);
myda.Fill(ds);
conn.Close();
subcatlist.DataSource = ds;
subcatlist.DataTextField = "subcategoryname";
subcatlist.DataValueField = "subcategory_id";
subcatlist.DataBind();
subcatlist.Items.Insert(0, new ListItem("select", "0"));
}
protected void FillPage1()
{
ArrayList adlist = new ArrayList();
string sub = subcatlist.SelectedValue.ToString();
string cit = null;
adlist = conclass1.getadbycat(sub, cit);
Panel linkpanel = new Panel();
int a = 0;
foreach (adclass ad in adlist)
{
Button viewbutton = new Button();
Label op = new Label();
StringBuilder sb = new StringBuilder();
HyperLink link = new HyperLink();
viewbutton.Click += new EventHandler(viewbutton_Click);
sb.Append(
string.Format(
@"
<img runat="server" src='{6}' /> | Title:
|
Id: {0} Price: {2} Rs Type: {3} Description: {4} Posted by: {5} {5}
", ad.product_id, ad.title, ad.price, ad.type, ad.description, ad.email_username, ad.imagepath));
if (sb.ToString() != "")
op.Text = sb.ToString();
else
op.Text = "No Results";
viewbutton.Text = "View ad";
link.NavigateUrl = "~/userpage.aspx";
linkpanel.Controls.Add(op);
linkpanel.Controls.Add(viewbutton);
}
panelop.Controls.Add(linkpanel);
}
protected void viewbutton_Click(object sender, EventArgs e)
{ Response.Write("hello");
Response.Redirect("login.aspx");
}
protected void FillPage()
{
ArrayList adlist = new ArrayList();
string sub = subcatlist.SelectedValue.ToString();
string cit = citylist.SelectedValue.ToString();
adlist = conclass1.getadbycat(sub,cit);
int a = 0;
Panel linkpanel = new Panel();
foreach (adclass ad in adlist)
{
Label op = new Label();
StringBuilder sb = new StringBuilder();
Button viewbutton = new Button();
adv = ad.product_id.ToString();
usr=ad.email_username.ToString();
sb.Append(
string.Format(
@"
<img runat="server" src='{6}' /> | Title:
|
Id: {0} Price: {2} Rs Type: {3} Description: {4} Posted by: {5} {5}
", ad.product_id, ad.title, ad.price, ad.type, ad.description, ad.email_username, ad.imagepath));
if (sb.ToString() != "")
op.Text = sb.ToString();
else
op.Text = "No Results";
viewbutton.Text = "View Ad";
// viewbutton.Click += new EventHandler(viewbutton_Click);
viewbutton.Command += new CommandEventHandler(this.viewbutton_Click);
viewbutton.CommandArgument = ad.email_username.ToString();
linkpanel.Controls.Add(op);
linkpanel.Controls.Add(viewbutton);
}
panelop.Controls.Add(linkpanel);
}
protected void viewbutton_Click(object sender, CommandEventArgs e )
{
Response.Redirect("homepage.aspx");
Response.Write(e.CommandArgument.ToString());
}
protected void subcatlist_SelectedIndexChanged(object sender, EventArgs e)
{
FillPage1();
if(!IsPostBack)
FillDropDownList1();
}
protected void citylist_SelectedIndexChanged(object sender, EventArgs e)
{
FillPage();
}
}
}
thanks in advance