Click here to Skip to main content
14,935,198 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
Member 10926063 24-Sep-16 4:45am
   
Datasource is result return from SP mentioned above.

When I bind gridview with dataset of above SP ,I m getting result of first select statement only ,which is quite obvious. Thus it need to be converted into datatable.Now I m getting result from all select statement using dt[0],dt[1],dt[2].this is OK. But I need to display above DT inside gridview lable using lables.
Karthik_Mahalingam 24-Sep-16 4:49am
   
so you will show only 3 count data in the grid, nothing apart from that?
Member 10926063 24-Sep-16 5:12am
   
No, I have nested gridview and on click of parent gridview itemtemplate (which contact date ,lable for count 1and lable for count 2),child grid is open.
Member 10926063 24-Sep-16 11:36am
   
Please help me out.
Karthik_Mahalingam 25-Sep-16 2:07am
   
Always use  Reply   button to post comments/query to the concerned user, so that the user gets notified and respond to your text.
Member 10926063 25-Sep-16 11:01am
   
Thanks for your suggestion, but I m still in search for solution of above problem.

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>
   

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