Hello,
The code as described above is slightly confusing. You have two event handlers. The first increases the variable
v_total
with 1, while the second fills a dataset with an SQL query from a database. Then, you bind that dataset as a datasource to the gridview. The bit that I'm missing is where you want to use the
v_total
in your gridview. You can only bind one datasource to your gridview so you'll have to bind your value directly to a column or cell. If you want to , for example, bind that value to a particular label in your gridview, you could try something like this :
<asp:GridView ID="gridProgress" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Total Value">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%" />
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblTotalValue" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Use the FindControl property of Gridview :
Label lbl = GridView3.Rows[rowIndex].FindControl("lblTotalValue") as Label;
lbl.Text = Convert.ToString(v_total);
Of course, you could bind your value to other controls inside your gridview as well. You could also add your value
v_total
to the dataset ( or datatable (works cool as datasource as well)) and then bind it directly to the gridview. Hope this helps.