QueryStrint
FIrstForm
public partial class QueryStringParams1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection Cn = new SqlConnection(
"Data Source=.;Initial Catalog=anil;Persist Security Info=True;User ID=sa;Password=123");
SqlDataAdapter Da = new SqlDataAdapter(
"select * from dept", Cn);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Dept");
GvDept.DataSource = Ds.Tables["Dept"];
GvDept.DataBind();
GvDept.DataKeyNames =
new string[] { "Deptno" };
}
protected void GvDept_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GvDept.SelectedIndex=e.NewSelectedIndex;
string Dno = GvDept.SelectedValue.ToString();
Server.Transfer(
"~/QueryStringParams2.Aspx?Dno=" + Dno);
}
Form2
Take a Grid View
public partial class QueryStringParams2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string Dno = Request.QueryString["Dno"];
SqlConnection Cn = new SqlConnection(
"Data Source=.;Initial Catalog=anil;Persist Security Info=True;User ID=sa;Password=123");
SqlCommand Cmd = new SqlCommand(
"select * from emp where deptno=" + Dno, Cn);
Cn.Open();
SqlDataReader Dr = Cmd.ExecuteReader();
GvEmp.DataSource = Dr;
GvEmp.DataBind();
Cn.Close();
}