.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

binding datalist from gridview

Posted By: Creator     Posted Date: April 13, 2010    Points:2   Category :.NET Framework
HI al..
i wanna display a selected row from gridview into datalist in another page... please tel me c# codebehind for the same using VS2005 n MySql database
thank you

Author: Creator             
Posted Date: April 13, 2010     Points: 5   

i got the solution.. instead of datalist use details view...

code for redirected aspx.cs page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.Types;
using MySql.Data.MySqlClient;

public partial class Default2 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)
if (Session["test"] != null)
string Id = Session["Id"].ToString();
string host = "localhost";
string database = "information";
string user = "root";
string password = "root";

string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;

MySqlConnection mysqlCon = new MySqlConnection(strProvider);

string strSQL = "Select * FROM customer WHERE Id=@Id";

MySqlCommand mysqlCmd = new MySqlCommand(strSQL, mysqlCon);
mysqlCmd.Parameters.AddWithValue("@Id", Id);
DataSet dSet = new DataSet();
MySqlDataAdapter dAd = new MySqlDataAdapter(mysqlCmd);
dAd.Fill(dSet, "SampleTable");
DetailsView1.DataSource = dSet;
DetailsView1.Visible = true;

protected void LinkButton1_Click(object sender, EventArgs e)

code for current page where selectedindexchanged event occurs

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
Session["test"] = "Test String";
DataSet ds = BindGrid();
GridView1.DataSource = ds;

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
GridViewRow row=GridView1.SelectedRow;
string age = row.Cells[1].Text;
Session.Add("age", age);


Author: Venkat             
Posted Date: April 14, 2010     Points: 5   


Thanks for sharing the solution. I was thinking the logic.

Mark As Answer if this solve your problem
Warm Regards,
Author: Sagar Pardeshi             
Posted Date: April 14, 2010     Points: 5   

hi friend

check following code

DataList DataList1 = this.ReturnControl("DataList1", GridView1) as DataList;
DataSet DS = new DataSet();
DataList1.DataSource = DS;

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend