Dynamic Gridview binding c#

Posted by Rajasekhar0544 under ASP.NET on 1/3/2013 | Points: 10 | Views : 11636 | Status : [Member] | Replies : 7
Hi All,

I have problem in gridview databinding,

private void fillgrid()
{
dsReports.Tables.Add(dtReport); //datatable is add here with 3 columns say count,hour,date
gvReport.DataSource = dsReports;
gvReport.DataBind(); //after binding the data im missing date column in gridview
}

As it is a dynamic gridview, autogenerate columns property is set to true

Plz help me.




Responses

Posted by: Chikkanti on: 1/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi see this...
http://chikkanti.wordpress.com/2011/11/11/editupdatedelete-in-gridview-using-edm-with-linq/

chikkanti

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanth.Gottipati on: 1/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,Pls try to below logic...........
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("Count", typeof(string)));
dt.Columns.Add(new DataColumn("hour", typeof(string)));
dt.Columns.Add(new DataColumn("date", typeof(string)));

dr["Count"] = grdview.Rows[row.RowIndex].Cells[1].Text.ToString();
dr["hour"] = grdview.Rows[row.RowIndex].Cells[2].Text.ToString();
dr["date"] = System.DateTime.Now.ToString("dd/MM/yyyy");

dt.Rows.Add(dr);
gvReport.DataSource = dt;
gvReport.DataBind();

(OR)

if get the values from the data base table write stored procedure and call that procedure to dataset and add that dataset gridview.

Ex: dataset ds=new dataset();
ds="select count,hour,date from tablename";
gvReport.DataSource = ds;
gvReport.DataBind();



Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chikkanti on: 1/8/2013 [Member] Starter | Points: 25
Posted by: Shubh on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Friend

i think it helps you...
on button click event.....
 con.Open(); //open your Sql connection

MySqlCommand cmd = new MySqlCommand("select * from Your_table", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView2.DataSource = dt; //now store data table
GridView2.DataBind(); //and finally bind the data with data grid you

con.Close();

Shubham Agrahari

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shubham on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
ya rajesh !!!! Shubh is right
only pass the connecting string on it

Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 1/14/2013 [Member] Starter | Points: 25

Up
0
Down
Hi rajesh,

Hemanth.Gottipati give a code u implement that code. if u face the same issue let us know.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hornstalk on: 10/16/2013 [Member] Starter | Points: 25

Up
0
Down
Bind GridView to data in C# Windows Forms application.
http://www.kettic.com/winforms_ui/csharp_guide/gridview_populate_data.shtml

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response