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


Top 5 Contributors of the Month
david stephan

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

Responses
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";

mysqlCon.Open();
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.DataBind();
DetailsView1.Visible = true;
}

}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("default.aspx");
}
}

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;
GridView1.DataBind();
}
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row=GridView1.SelectedRow;
string age = row.Cells[1].Text;
Session.Add("age", age);
//Response.Redirect("Default2.aspx");
Server.Transfer("Default2.aspx");

}

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

HI,

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

Mark As Answer if this solve your problem
Warm Regards,
Venkat
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();
DS.Tables.Add("oDataTableChapter");
DataList1.DataSource = DS;
DataList1.DataBind();




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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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