Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
actually i'am using grid view in that it head retrieve sum textboxs and dropdownlists details i planing to add one button at last of the row last column

What I have tried:

ASP.NET
<asp:TemplateField HeaderText="save"
                    <ItemTemplate>
                   < FooterStyle HorizontalAlign="Right" VerticalAlign="Bottom"                     FooterTemplate >
                 <       asp:Button ID="Button1" runat="server" Text="save" >
                   < FooterTemplate > 
                  <ItemTemplate>
             <  asp:TemplateField >


i'am trying this but the save button is add on every row off the last column.
please give me hints
Posted
Updated 2-Sep-16 1:14am
v9
Comments
Karthik_Mahalingam 5-May-16 2:26am
   
check my updated solution.
Nagarjuna99 5-May-16 2:36am
   
i have another doubt that is i'am taking save button,what my requirement i press save button the the multiple number of rows will be save on database ?
is it possible?

try this

ASP.NET
<asp:GridView ID="GridView1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
           <Columns>
               <asp:BoundField DataField="itemname" HeaderText="itemname" />
               <asp:BoundField DataField="itemprice" HeaderText="itemprice" />
               <asp:BoundField DataField="quantity" HeaderText="quantity" />
               <asp:BoundField DataField="tax" HeaderText="tax" />
               <asp:TemplateField  HeaderText="finalamount">
                   <ItemTemplate>
                       <asp:Label  Text='<%# Eval("finalamount") %>' runat="server" />
                   </ItemTemplate>
                   <FooterTemplate>
                       <asp:Button Text="Save" runat="server" />
                   </FooterTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>
   
v2
Comments
Nagarjuna99 5-May-16 2:44am
   
button was not added
Karthik_Mahalingam 5-May-16 2:55am
   
ShowFooter="true"
Nagarjuna99 5-May-16 2:57am
   
show footer="true",now its working,
i'have another question when i press button ,the multiple rows of data will be save in database? how to do this
Karthik_Mahalingam 5-May-16 3:07am
   
check this
you will get.Insert all gridview data into a table[^]
Nagarjuna99 5-May-16 5:34am
   
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string name = GridView1.Rows[i].Cells[0].Text;
string price = GridView1.Rows[i].Cells[1].Text;
string quantity = GridView1.Rows[i].Cells[2].Text;
string tax = GridView1.Rows[i].Cells[3].Text;
string final = GridView1.Rows[i].Cells[4].Text;


SqlConnection con = new SqlConnection("Data Source=XENORIX8-PC;Initial Catalog=xenorix;User ID=sa;Password=123");
string str = "insert into quantity1 values('" + name + "','" + price + "','"+quantity+"','"+tax+"','"+final+"')";
SqlCommand strCmd = new SqlCommand(str, con);
con.Open();
strCmd.ExecuteNonQuery();
con.Close();

}
i'am using this code to save grid view data into database ,but it has one problem that is final amount will save on 0.00.i think its not taking label 6 value off final amount what i do now?
Karthik_Mahalingam 5-May-16 5:36am
   
keep break point and check line by line why the value is getting 0
Nagarjuna99 5-May-16 5:39am
   
<asp:TemplateField HeaderText="finalamount">
<itemtemplate>
<asp:Label Text='<%# Eval("finalamount") %>' runat="server" />

<footertemplate>
<asp:Button Text="Save" runat="server" />


i think this label 6 value not taking.
Karthik_Mahalingam 5-May-16 5:48am
   
you should cast the value..
http://stackoverflow.com/a/10903924/1147428
Any control you add in footer will show in footer only. You are not doing it properly.
This is very basic thing. You need to go through some tutorial documents.

Inserting a New Record from the GridView's Footer (C#) | The ASP.NET Site[^]

Working with Footer Template in Gridview. - DotNetFunda.com[^]

Displaying Summary Information in the GridView's Footer (VB) | The ASP.NET Site[^]


[Edit]

ASP.NET
<asp:TemplateField HeaderText="Your header text">
                        <ItemTemplate>
                         <!-- your template control -->
                        </ItemTemplate>                       

                        <FooterTemplate>
                           <asp:Button ID="Button1" runat="server" Text="save" />
                        </FooterTemplate>
                    </asp:TemplateField>
   
v3
Comments
Nagarjuna99 5-May-16 2:00am
   
i now but ,the html code was not coming properly in that so i removeing,
<asp:TemplateField HeaderText="save">
<itemtemplate>
<footerstyle horizontalalign="Right" verticalalign="Bottom">
<footertemplate>
<asp:Button ID="Button1" runat="server" Text="save" />



this is my code
please and check what i wrong
Nagarjuna99 5-May-16 2:01am
   
<asp:TemplateField HeaderText="save">
<itemtemplate>
<footerstyle horizontalalign="Right" verticalalign="Bottom">
<footertemplate>
<asp:Button ID="Button1" runat="server" Text="save" />


Raje_ 5-May-16 2:07am
   
check my edited answer. You see i have taken separate footer template for button.
Nagarjuna99 5-May-16 2:47am
   
in that case button was not displaying
Raje_ 5-May-16 2:50am
   
Did you add ShowFooter="true" to your grid view???
Raje_ 5-May-16 2:52am
   
You did not go through the links i have provided. Did you?
Nagarjuna99 5-May-16 2:54am
   
ya now i'am adding show footer="true,its working .thanks @Raje_
Raje_ 5-May-16 2:55am
   
Even now i will ask you to go through those links. You have lot to learn yet :)
My best wishes to you.
Nagarjuna99 5-May-16 2:58am
   
okey i will try as my best,thanks for giving this instractions
How to calculate time column .. Like if we have 2 column of datetime i want to multiply both columns value in 3rd column...How to do it?
   

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