the title of the thread says it all.
how?
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
Lalit MRank #1,186 · 1.5K reputationPosted Nov 26, 2009, 10:46 PM EST
You can use this code sample for Select GridView Row to DataTable
using System;
using System.Data;
using System.Configuration;
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.Web.Configuration;
using System.Data.SqlClient;
///
/// Summary description for GridViewToDataTable
///
namespace DotNetTutorials.Tutorial
{
public class GridViewToDataTable
{
///
/// Default constructor for GridViewToDataTable
///
public GridViewToDataTable()
{
}
///
/// Gets all columns from Table1
///
///
public static DataTable GetAllData()
{
DataTable allData = new DataTable();
SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
try
{
SqlCommand cmd = new SqlCommand("GetAllData", connection);
cmd.CommandType = CommandType.StoredProcedure;
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(allData);
connection.Close();
}
catch
{
connection.Close();
}
return allData;
}
}
}
You can also show this article from this link
For more info Q/A.
Mark Uy130 reputationPosted Nov 26, 2009, 10:55 PM EST
what does the line "namespace DotNetTutorials.Tutorial" mean?
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 26, 2009, 10:58 PM EST
First you should make sure the columns in datatable and datagridview are same.
Then you can use following code.
if (dataGridView1.SelectedRows == null)
return;
DataGridViewRow row = dataGridView1.SelectedRows[0];
if (row != null)
{
DataRow r = dtable.Rows.Add(row.Cells[0].Value, row.Cells[1].Value);
dtable.AcceptChanges();
}
If this helps you, please do not forget to mark Do you like this answer checkbox.
shyamala37 reputationPosted Nov 26, 2009, 11:35 PM EST
protected void LinkButton_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridViewRow Gvrow = (GridViewRow)lb.Parent.Parent;
string id1= GridView1.DataKeys[Gvrow.RowIndex].Values["id"].ToString();
Response.Redirect("nextpage.aspx?vprofile=" + id1);
}
shyamala37 reputationPosted Nov 26, 2009, 11:39 PM EST
dt=con.DBExecute("select * from tablename where id='"+id+"'");
Datalist.DataSource=dt;
Datalist.DataBind();