Click here to Skip to main content
16,005,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
{1}

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:
{1}

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
Posted
Updated 26-Mar-14 9:21am
v2
Comments
ZurdoDev 26-Mar-14 14:40pm    
What's the question?
Kiran Joseph Cdz 26-Mar-14 15:20pm    
i need the display the output(the ads- dynamic data) in pages according to the amount of records selected...i.e for large amount of selected records , i need the output not in a single page...so plz help
ZurdoDev 26-Mar-14 15:32pm    
I don't understand where you are stuck. What can I do to help?
Kiran Joseph Cdz 26-Mar-14 15:59pm    
now when i run the page...the ads appear in a single path despite the no.of ads. i need to display some amount of data i.e the ads in 1 page. and if there is large amount of data
i need to display it in next page...anyway thanks

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900