the title of the thread says it all.
how?
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.
shyamalaPosted Nov 27, 2009, 4:39 AM
dt=con.DBExecute("select * from tablename where id='"+id+"'");
Datalist.DataSource=dt;
Datalist.DataBind();
shyamalaPosted Nov 27, 2009, 4:35 AM
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);
}
Nilanka DharmadasaPosted Nov 27, 2009, 3:58 AM
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.
Mark UyPosted Nov 27, 2009, 3:55 AM
what does the line "namespace DotNetTutorials.Tutorial" mean?
Lalit MPosted Nov 27, 2009, 3:46 AM
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.