A data representation control like
GridView
can only handle one
DataSource
at a time. Since your data is coming from different tables, then you may need to join those table so you can select columns from the joined tables and make that as the final result from you SP. Alternatively, you can query those tables, just like what you did currently and create a custom
DataTable
in your code that would holds all the columns you need from the two tables. You could then use that custom
DataTable
as your final
DataSource
.
Here's a quick example:
private void BindGrid(DataSet ds)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("MarkedCount", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("LegalCount", typeof(String)));
dt.Columns.Add(new System.Data.DataColumn("NotLegalCount", typeof(String)));
DataTable firstResult = ds.Tables[0];
DataTable secondResult = ds.Tables[1];
DataTable thirdResult = ds.Tables[2];
if (firstResult.Rows.Count > 0){
dr = dt.NewRow();
dr[0] = firstResult.Rows[0][0].ToString();
dr[1] = secondResult.Rows[0][0].ToString();
dr[2] = thirdResult.Rows[0][0].ToString();
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
The
DataSet
parameter will hold the data from your SP. Once you've got that, you should be able to use the columns defined from the custom
DataTable
, and use that to bind your Control within
ItemTemplate
.
<itemtemplate>
<asp:label id="Label1" runat="server" text="<%# Bind("MarkedCount") %>">
</asp:label></itemtemplate>