Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have gridview that bind with data table.This datatable is fill with SQL procedure that contain 3 select statement(return count's) with where clause. I need to show these count's return from 3select statement inside gridview itemtemplate on labels.This must be done in aspx page using eval<%count1%>.
Please Help , new to asp gridview.

What I have tried:

Bind gridvw.dataset();
In aspx page gridview itemtemplate
Posted
Updated 26-Sep-16 8:01am
Comments
Karthik_Mahalingam 24-Sep-16 2:16am    
what is the result of the sp?
each result will have only the count or data also?
Member 10926063 24-Sep-16 3:37am    
SP return 3 result set, which contains statement like below.

Select count(patent) from table1 where lslegal=1 and Is marked=1

Select count(patent) from table1 where patentlegal=1

Select count(patent) from table1 where patentIsNotlegal=1

gridview is bind above dataset result.
Karthik_Mahalingam 24-Sep-16 4:35am    
why do you need gridview to display the count, you shall use label right?
Member 10926063 24-Sep-16 4:40am    
I m using lable which reside inside gridview itemtemplate.
Gridview row display look like below.
1-7-16 7 Done 1 Not Done
Karthik_Mahalingam 24-Sep-16 4:41am    
what is the datasource for the gridivew

1 solution

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:

C#
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.

ASP.NET
<itemtemplate>
        <asp:label id="Label1" runat="server" text="<%# Bind("MarkedCount") %>">
</asp:label></itemtemplate>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900