anil babu

anil babu

  • NA
  • 111
  • 62.2k

Redirect page based on query string parameter?

Oct 3 2012 10:06 PM

I am trying but open in next window

I  am clicking selecting in QueryStringParams1.Aspx  page ,second page url like this http://localhost:3951/query/QueryStringParams2.Aspx?TagId=1

Based on that TagId query string value will open In the browser in the same window(Ex:www.asp.net)

After that URL same http://localhost:3951/query/QueryStringParams2.Aspx?TagId=1,I want to chnge TagId=2 based on that TagId value open in the same page(EX:www.bing.com) and so on

Table like this in database

TagId NAME coupounurl
1       asp      www.asp.net
2      weblog  www.bing.com
3      google   www.google.com

Default.aspx
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="Gvurl" runat="server" AutoGenerateSelectButton="True" AutoGenerateColumns="false"
onselectedindexchanging="GvDept_SelectedIndexChang ing" Width="227px">
</asp:GridView>
</div>
</form>
</body>
</html>
.CS
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection( @"Data Source=<>;Initial Catalog=productdb;Persist Security Info=True;User ID=<>;Password=<>"); 

SqlDataAdapter da = new SqlDataAdapter("select * from redirecturl", con);

DataSet ds = new DataSet();
da.Fill(ds, "redirecturl");
Gvurl.DataSource = ds.Tables["redirecturl"];
Gvurl.DataBind();
Gvurl.DataKeyNames = new string[] { "Tagid" };
}
protected void GvDept_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
Gvurl.SelectedIndex = e.NewSelectedIndex;

string Dno = Gvurl.SelectedValue.ToString();

Response.Redirect("~/QueryStringParams2.Aspx?TagId="+Dno);

}
QueryStringParams2.Aspx
<!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></title>
<script>

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvRed" runat="server" 
EmptyDataText="There Are No Employees In Selected Department" 
AutoGenerateColumns="false" Width="99px">
<%--<Columns>
<asp:TemplateField HeaderText="Redirect URL">
<ItemTemplate>
<a href='<%#Eval("coupounurl") %>'><%#Eval("coupounurl")%></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>--%>
</asp:GridView>
<br />
</div>
</form>
</body>
</html>
.CS
public partial class QueryStringParams2 : System.Web.UI.Page
{

String URL = "";
protected void Page_Load(object sender, EventArgs e)
{
string Dno = Request.QueryString["TagId"];

SqlConnection con = new SqlConnection( @"Data Source=<>;Initial Catalog=productdb;Persist Security Info=True;User ID=<>;Password=<>");

SqlCommand cmd = new SqlCommand("select coupounurl from redirecturl where customerid=" + Dno, con);

con.Open();

SqlDataReader dr = cmd.ExecuteReader();
GvRed.DataSource = dr;
GvRed.DataBind();
dr.Close();

object drReader = cmd.ExecuteScalar();
if (drReader != null)
{
URL = drReader.ToString();
}
con.Close();
if (!String.IsNullOrEmpty(URL))
{
Response.Write("<script language='javascript'>window.open('" + URL + "','_newtab');</script>");
}
}

I can try this one plz tel me



Attachment: query.rar