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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Mar 13, 2013, 5:28 AM
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();
}
}
}
AbhiPriya M VPosted Mar 14, 2013, 2:56 AM
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..
Vishal GilbilePosted Mar 13, 2013, 6:18 AM
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.
darma tejaPosted Mar 13, 2013, 6:12 AM
dataGridView1[0, e.RowIndex].Value // you get row value that you are selected in gridview
AbhiPriya M VPosted Mar 13, 2013, 4:46 AM
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!!!
Satyapriya NayakPosted Mar 13, 2013, 4:42 AM