You must Sign In to post a response.
  • Category: ASP.NET

    Pass values Using OueryString

    Hello developers,
    I want to pass the values, user level page to admin level page which is already Stored in the database.then i need to insert the same value in another please give some examples for how i am done it.

    Thanks with
  • #762479


    If you need insert records one table to another table means use this


    SELECT *
    INTO Manual table
    FROM Records have table;

    You can use this Query

    SELECT * INTO tables1001 FROM [Atbls1]

    If you need passing Query String means

    try this Code


    ViewState["Empno"] = Request.QueryString["EmpName"].ToString();

    2. Session

    Session["Empno"] = Request.QueryString["EmpName"].ToString();
    Session.Add("EmpNo", Request.QueryString["EmpName"].ToString());

    3. Hidden Field

    HiddenField reg = new HiddenField();
    reg.Value = Request.QueryString["EmpName"].ToString();

    4. Application

    //Application Mostly assign in our project Global.asax file.
    Application.Add("EmpName", Request.QueryString["EmpName"].ToString());

    Step2:- Pass the data via Query string using Client Side Code use this code(C#)

    <asp:GridView ID="Grd1" runat="server">
    <asp:BoundField DataField="Id" HeaderText="" />
    <asp:BoundField DataField="EmpNo" HeaderText="" />
    <asp:BoundField DataField="EmpName" HeaderText="" />
    <asp:BoundField DataField="Amount" HeaderText="" />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("WebForm7.aspx?Id={0}&EmpNo={1}&EmpName={2}",
    HttpUtility.UrlEncode(Eval("Id").ToString()), HttpUtility.UrlEncode(Eval("EmpNo").ToString()), HttpUtility.UrlEncode(Eval("EmpName").ToString())) %>'
    Text="View Details" />

    Step3: Pass the data via Query string using Server Side Code (C#)

    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[4] {new DataColumn("Id"), new DataColumn("EmpNo"),new DataColumn("EmpName"),new DataColumn("Amount") });
    dt.Rows.Add(1, 1500,"John", 7500);
    dt.Rows.Add(2, 2500, "Wesly", 8500);
    dt.Rows.Add(3, 4500, "Ruseel", 9500);

    Grd1.DataSource = dt;

    protected void Button1_Click(object sender, EventArgs e)
    Response.Redirect("WebForm7.aspx?EmpNo" + TxtEmpno.Text);

    DataTable dt = new DataTable();
    if (dt.Rows.Count > 0)
    Response.Redirect("WebForm7.aspx?EmpName=" + dt.DefaultView[0]["EmpName"].ToString());

    Response.Redirect("Default2.aspx?EmpName=" +TxEmp.Text + "&EmpNo=" + TxEmpNo.Text+ "&EId=" + TxEID.Text );

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762491
    QueryStrings are separated by & symbol.
    If we want more than one value to be passed in QueryString then we should use "&" between two QueryStrings.

    With in the Button1_Click event of Default.aspx, am sending three values Name, Password and Id for second webpage Default2.aspx with in the url.

    protected void Button1_Click(object sender,
    EventArgs e)
    Response.Redirect("~/Default2.aspx?Name=" +
    TextBox1.Text + "&Password=" + TextBox2.Text + "&Id=" + TextBox3.Text );

    To read a QueryString value we use Request.QueryString.
    Session["Name"] = Request.QueryString["EmpName"].ToString();
    Session["id"] = Request.QueryString["EmpNo"].ToString();

    Sridhar Thota.
    Editor: DNS Forum.

Sign In to post your comments