Click here to Skip to main content
15,849,615 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
actually i have sending parameter to the another page using queery string.in this we have using
2 tables

table1:Dept
Did varchar(50)-primarykey notnull

Dname varchar(50)-null

Dproduct varchar(50)-null

table2:Emp

Empid varchar(50) null

Ename varchar(50) null

Esal varchar(50) null

i have taken gridview on page and whenever select value using index postion that value(parameter) will passing to the another page that page have another gridview.my intation is another gridview taken parameter and display gridview.we have using two tables for each gridview. but my probelm is parameter will sending to the another gridview.error will be there


"parameter is in valid"


my code like as




HTML
first gridview page

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class varbyparam : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader dr; 
    protected void Page_Load(object sender, EventArgs e)
    {
        bind();
    }
    public void bind()
    {
        con = new SqlConnection("Data Source=SANKALPA-PC;Initial Catalog=EmpDept;Integrated Security=True");
        con.Open();
        cmd = new SqlCommand("select * from Dept", con);
        dr = cmd.ExecuteReader();      
        Gridview1.DataSource = dr;
        Gridview1.DataBind();
        Gridview1.DataKeyNames = new string[] { "Did" };
        con.Close();
        dr.Close();
        
    }

    protected void Gridview1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        Gridview1.SelectedIndex = e.NewSelectedIndex;
        string Did= Gridview1.SelectedValue.ToString();
        Response.Redirect("~/param1.aspx?Did="+Did);
    }
}

second gridview page

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class param1 : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {
        //string Deptid = Request.QueryString["Did"].ToString();
        con = new SqlConnection("Data Source=SANKALPA-PC;Initial Catalog=EmpDept;Integrated Security=True");
        con.Open();
        string sql = "select * from Emp where Did=" + Request.QueryString["Did"].ToString();
        cmd = new SqlCommand(sql,con);
        dr = cmd.ExecuteReader();
        Gridview2.DataSource = dr;
        Gridview2.DataBind();       
        con.Close();
    }
}
Posted
Comments
♥…ЯҠ…♥ 21-Feb-14 9:20am    
What do you get in Request.QueryString["Did"].ToString(); here?

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