Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void Page_Load(object sender, EventArgs e)
{
int j = Convert.ToInt32(Request.QueryString["Cat_Id"]);
int i = Convert.ToInt32(Request.QueryString["Sub_Cat_Id"]);


SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");

con.Open();

SqlDataAdapter cmd = new SqlDataAdapter("SELECT AD_ID,AD_TITLE, AD_DESC, AD_IMG, AD_PRICE, AD_NO, SUB_CAT_DESC, CAT_DESC, SELLER_NAME, SELLER_MOB_NO, SELLER_EMAIL_ID, SELLER_DEP, SELLER_FLOOR,DATE FROM AD_DETAIL_V WHERE (DATE >= { fn CURDATE() }) and BUY_SELL_ID='1' and DELETED_AD = '0' AND SUB_CAT_ID= " + i + "AND CAT_ID =" + j, con);
DataSet ds = new DataSet();
cmd.Fill(ds);
gvImages.DataSource = ds;
gvImages.DataBind();

}


i and j are the cat_id & Sub_cat_ID of the result page i want it to redirect to home page if the cat_ID & Sub_Cat_doesn't exists.

Example - http://localhost:50476/SamsungClassifieds/Results.aspx?Cat_Id=4&Sub_Cat_Id=10000
it will redirect to homepage.
Posted
Comments
Member 10543194 25-Jan-14 2:38am    
hOW TO display a data of id and its sub ids in treeview
Member 10543194 25-Jan-14 2:40am    
this is my code it not displaying all of it

private void button2_Click(object sender, EventArgs e)
{
l:

try
{

con = new OleDbConnection(cs);
con.Open();
//Sales.ReferenceID = Customer.CustomerID and
cmd = new OleDbCommand("SELECT * from Sales where CustomerID='" + textBox22.Text + "' order by CustomerID ASC ", con);
OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);
DataTable rdr = new DataTable();
myDA.Fill(rdr);

for (int i = 0; i < rdr.Rows.Count; i++)
{
TreeNode node = new TreeNode(rdr.Rows[i]["CustomerNameSales"].ToString());
node.Nodes.Add(rdr.Rows[i]["ReferenceID"].ToString());
node.Nodes.Add(rdr.Rows[i]["CustomerID"].ToString());
node.Nodes.Add(rdr.Rows[i]["Rank"].ToString());
node.Nodes.Add(rdr.Rows[i]["checkcol"].ToString());
treeView1.Nodes.Add(node);
}


con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

try
{

con = new OleDbConnection(cs);
con.Open();
String ct102000 = "SELECT CustomerID from Sales where ReferenceID = '" + textBox22.Text + "'";
cmd = new OleDbCommand(ct102000, con);
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


if ((rdr.Read() == true))
{

textBox21.Text = (rdr["CustomerID"].ToString());
textBox22.Text = textBox21.Text;

if (textBox22.Text != null)
{
goto l;

}

goto l;
}

con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}



}
give me a solution

You have to check first the count of the tables in your DataSet. If it is zero redirect to the homepage.

C#
DataSet ds = new DataSet();
cmd.Fill(ds);

int count = ds.Tables[0].Rows.Count;

if (count == 0)
   Response.Redirect("HomePage.aspx");

gvImages.DataSource = ds;
gvImages.DataBind();


Thank you hypermellow[^]!

I hope it could help! Let me know if something is wrong!
 
Share this answer
 
v10
Comments
Harshit Wadhera 16-Sep-13 10:23am    
sir this an example i want all that Category id and Sub Category ID to be redirect to home page if it is not exists..

Example - http://localhost:50476/SamsungClassifieds/Results.aspx?Cat_Id=4&Sub_Cat_Id=1
it will redirect to Result page - Because this cat and sub_cat id exists.

but http://localhost:50476/SamsungClassifieds/Results.aspx?Cat_Id=4&Sub_Cat_Id=1222 doesn't exists . therefore it will redirect to result page.
norbitrial 16-Sep-13 10:28am    
If i understood well if in your dataset there are no record the page should redirect to the homepage. I have improved my solution.
Harshit Wadhera 16-Sep-13 10:32am    
yes sir you understood but its not working
Harshit Wadhera 16-Sep-13 10:31am    
cmd.Fill(ds);
gvImages.DataSource = ds;
gvImages.DataBind();

int count = ds.Tables.Count;

if (count == 0)
{
Response.Redirect("HomePage.aspx");
}
}
}

Sir i have write this code but its not working
hypermellow 16-Sep-13 10:41am    
Try replacing:

int count = ds.Tables.Count;

with:

int count = ds.Tables[0].Rows.Count;
This Code will redirect to HomePage Whatever we will write in the Url of ResultPage. i.e Alphabet,Numbers,Remove whole Url after ?......



protected void Page_Load(object sender, EventArgs e)
{

int iCatID;
int iSubCatID;
string j = Request.QueryString["Cat_Id"];
string i = Request.QueryString["Sub_Cat_Id"];

SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
con.Open();
if (i == null && j == null)
{
Response.Redirect("HomePage.aspx");
}
else
if((int.TryParse(i.ToString(), out iCatID))&&(int.TryParse(j.ToString(), out iSubCatID)))
{
//Do your DB retrieval here .....
SqlDataAdapter cmd = new SqlDataAdapter("SELECT AD_ID,AD_TITLE, AD_DESC, AD_IMG, AD_PRICE, AD_NO, SUB_CAT_DESC, CAT_DESC, SELLER_NAME, SELLER_MOB_NO, SELLER_EMAIL_ID, SELLER_DEP, SELLER_FLOOR,DATE FROM AD_DETAIL_V WHERE (DATE >= { fn CURDATE() }) and BUY_SELL_ID='1' and DELETED_AD = '0' AND SUB_CAT_ID= " + iCatID.ToString() + "AND CAT_ID =" + iSubCatID.ToString(), con);
DataSet ds = new DataSet();
cmd.Fill(ds);
int count = ds.Tables[0].Rows.Count;
if (count == 0)

Response.Redirect("HomePage.aspx");

gvImages.DataSource = ds;
gvImages.DataBind();
}
else
{ //Handle the parameter type error (i.e. - display a message or redirect user)
Response.Redirect("HomePage.aspx");
}
}
 
Share this answer
 
hOW TO display a data of id and its sub ids in treeview
this is my code in c# and ms access data base it not displaying all of it

private void button2_Click(object sender, EventArgs e)
{
l:

try
{

con = new OleDbConnection(cs);
con.Open();
//Sales.ReferenceID = Customer.CustomerID and
cmd = new OleDbCommand("SELECT * from Sales where CustomerID='" + textBox22.Text + "' order by CustomerID ASC ", con);
OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);
DataTable rdr = new DataTable();
myDA.Fill(rdr);

for (int i = 0; i < rdr.Rows.Count; i++)
{
TreeNode node = new TreeNode(rdr.Rows[i]["CustomerNameSales"].ToString());
node.Nodes.Add(rdr.Rows[i]["ReferenceID"].ToString());
node.Nodes.Add(rdr.Rows[i]["CustomerID"].ToString());
node.Nodes.Add(rdr.Rows[i]["Rank"].ToString());
node.Nodes.Add(rdr.Rows[i]["checkcol"].ToString());
treeView1.Nodes.Add(node);
}


con.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

try
{

con = new OleDbConnection(cs);
con.Open();
String ct102000 = "SELECT CustomerID from Sales where ReferenceID = '" + textBox22.Text + "'";
cmd = new OleDbCommand(ct102000, con);
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


if ((rdr.Read() == true))
{

textBox21.Text = (rdr["CustomerID"].ToString());
textBox22.Text = textBox21.Text;

if (textBox22.Text != null)
{
goto l;

}

goto l;
}

con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}



}
give me a solution
 
Share this answer
 
Comments
CHill60 25-Jan-14 12:11pm    
If this is a question, then posting it as a solution to someone else's question will not get you much help. Use the "Ask a question" link to post your own question - and use "pre" tags to format your code when you do so.

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