code for passing the selected row value of an gridview to another gridview which is in another page???
thank u!!!!
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 13, 2013, 1:28 AM EDT
Another way
test1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="Display_related_records_gridview.test1" %>
test1.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_related_records_gridview
{
public partial class test1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
private void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
SqlDataReader reader;
reader = com.ExecuteReader();
g1.DataSource = reader;
g1.DataBind();
con.Close();
}
}
}
test2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="Display_related_records_gridview.test2" %>
test2.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_related_records_gridview
{
public partial class test2 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
string s1;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
try
{
con.Open();
s1 = Request.QueryString[0];
str = "select * from employee where empname='" + s1 + "'";
com = new SqlCommand(str, con);
g2.DataSource = com.ExecuteReader();
g2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
con.Close();
}
}
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 13, 2013, 12:42 AM EDT
AbhiPriya M V63 reputationPosted Mar 13, 2013, 12:46 AM EDT
using checkbox am selecting a row in a gridview...passing that selected row from one gridview to another gridview which s in another page..got it???
thank u!!!
darma tejaRank #3,199 · 449 reputationPosted Mar 13, 2013, 2:12 AM EDT
dataGridView1[0, e.RowIndex].Value // you get row value that you are selected in gridview
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 13, 2013, 2:18 AM EDT
If your gridview contains TemplateFields then kindly make use of Hyperlink field where you want to display Link on whose click it should redirect to next page passing certain values.
You will have to set the following properties of the Hyperlink field, They are as follows.
HeaderText:= The Text To be displayed as a Column Name Of GridView.
DataTextField:= The Text to be displayed as a Data (link) in the hyperlink column.
DataNavigateUrlFields:= The Column Name whose value you need to pass when the hyperlink is clicked.
and lastly
DataNavigateUrlFormatString:=The name of the page on which to redirect
eg: DataNavigateUrlFormatString=pageName.aspx?eid={0}
the place holder value will automatically be taken from the DataNavigateUrlField property which you specified above.
Hope that solves your problem.
With Regards,
Vishal Gilbile.
AbhiPriya M V63 reputationPosted Mar 13, 2013, 10:56 PM EDT
tried all ur replies but not yet got it!!
page s gng to next page but the values are not passed.getting just an empty page.no values..