A data representation control like
GridView
can only handle one
DataSource
at a time. Since your data is coming from different sources (database and code variable), then you may need create a custom
DataTable
that would holds all the information you need from your sources. You could then use that custom
DataTable
as your final
DataSource
for your
GridView
.
Here's a quick example: (PS: Never tested on this, but it should give you some idea)
private void BindGrid(DataDaTable source)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("Column1", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Column2", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("Column3", typeof(String)));
int rowCount = source.Rows.Count;
if ( rowCount > 0){
for(int i=0; i < rowCount; i++){
dr = dt.NewRow();
dr[0] = source.Rows[i]["ColumnName"].ToString();
dr[1] = source.Rows[i]["ColumnName"].ToString();
dr[2] = "Your custom variable value here";
dt.Rows.Add(dr);
}
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
Alternatively, you could just add a new
Column
to your existing
DataTable
something like:
DataColumn newColumn = new DataColumn("ColumnName", typeof(System.String));
newColumn.DefaultValue = "Your variable value";
dt.Columns.Add(newColumn);