I have problem in Gridview

Posted by Nuwan under ASP.NET on 1/14/2012 | Points: 10 | Views : 1059 | Status : [Member] | Replies : 5
Dear All,

I have Sql table it have mainly two fields Contract No & Amount. That Contract Number is Mainly categories two way
HP(Higher Perches) & LC(Leasing) . I want to bind that table in Gridview Like below

Contract Number Amount
LC001 100.00
LC002 200.00

Sub Total 300.00

HP001 100.00
HP002 100.00

Sub Total 200.00

Grand Total 500.00



Please Help this matter. Please provide coding sample.

Thank You....

Rathnayake


Responses

Posted by: Sksamantaray on: 1/15/2012 [Member] Silver | Points: 25

Up
0
Down
Try this...
http://www.dotnettwitter.com/2011/02/group-total-grand-total-in-grid-view.html

Thanks,
Sanjay

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

Posted by: Nuwan on: 1/15/2012 [Member] Starter | Points: 25

Up
0
Down
Thank You Sir, It is a Best Reply....

Rathnayake

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

Posted by: Nuwan on: 1/15/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sir.
Your Example is provide a Grouping in a Date, Bt i want it Contract Number,
My ContractNumber Format is LC & HP. How I convert it. Is i can use a Sql MID or Left Function.
Please Help me.....

Thank You....

Rathnayake

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

Posted by: Sksamantaray on: 1/15/2012 [Member] Silver | Points: 25

Up
0
Down


create table MyTable(id bigint,contactno varchar(20),amount bigint)


insert into MyTable values(1,'LC001',100)
insert into MyTable values(2,'LC002',200)
insert into MyTable values(3,'HP001',100)
insert into MyTable values(4,'HP002',100)

create procedure spMyTable
as
begin
select subTotal=SUM(Amount),left(contactno,2) 'ContactCategory' from MyTable group by left(contactno,2)
end

create procedure spMyTable2
@cat varchar(2)
as
begin
select *,left(contactno,2) 'ContactCategory' from MyTable
where left(contactno,2)=@cat
end
--------------------------------------------

<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Width="486px" ShowFooter="True"
>
<Columns>

<asp:TemplateField HeaderText="ContactCategory"
SortExpression="ContactCategory">



<ItemTemplate>
<asp:Label ID="Label2" Visible="false" runat="server" Text='<%# Bind("ContactCategory") %>'></asp:Label>
<br />
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>

<asp:BoundField DataField="contactno" HeaderText="contactno"
SortExpression="contactno" />
<asp:BoundField DataField="amount" HeaderText="amount"
SortExpression="amount" />

</Columns>
</asp:GridView>

<div style="background:#eee;">
SubTotal:
<asp:Label ID="sub" runat="server" Text='<%# Bind("subTotal") %>'></asp:Label>
</div>


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EMPConnectionString %>"
SelectCommand="spMyTable2" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="Label2" Name="cat" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
<FooterTemplate >
<asp:Label ID="lblSubT" runat="server" Text='<%# Bind("subTotal") %>'></asp:Label>
ssssssssssssssss

</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:EMPConnectionString %>"
SelectCommand="spMyTable" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

</div>
</form>


I have shown a sample you can bind data in your code behind.

Thanks,
Sanjay

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

Posted by: Nuwan on: 1/16/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks Sir.... Its very help for me.
any way thanks.....

Rathnayake

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

Login to post response