Hi,
just check this once you'll get an idea what i did
<div id="resdiv">0</div>
<br />
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
<columns>
<asp:templatefield>
<HeaderTemplate >
ID
</HeaderTemplate>
<itemtemplate>
<%#Eval("id") %>
</itemtemplate>
<footertemplate>
</footertemplate>
</asp:templatefield>
<asp:templatefield>
<HeaderTemplate >Value </HeaderTemplate>
<itemtemplate><![CDATA[</itemtemplate>
<footertemplate></footertemplate>
</asp:templatefield>
<asp:templatefield>
<HeaderTemplate >Add</HeaderTemplate>
<itemtemplate><input type ="checkbox" onclick='addthis(this,<%#Eval("value") %>)' /></itemtemplate>
<footertemplate></footertemplate>
</asp:templatefield>
</columns>
</asp:gridview>
And javascript file contains following code
function addthis(tid, val1) {
if (tid.checked) {
document.getElementById("resdiv").innerText = parseInt(document.getElementById("resdiv").innerText) + parseInt(val1);
}
else {
document.getElementById("resdiv").innerText = parseInt(document.getElementById("resdiv").innerText) - parseInt(val1);
}
}
And code behind file contains
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filldata();
}
}
public void filldata()
{
dt.Columns.Add("id");
dt.Columns.Add("value");
addrowin("1", "12");
addrowin("2", "45");
addrowin("3", "78");
addrowin("4", "85");
addrowin("5", "78");
addrowin("6", "15");
addrowin("7", "45");
addrowin("8", "98");
addrowin("9", "78");
GridView1.DataSource = dt;
GridView1.DataBind();
}
public void addrowin(string uid, string pid)
{
DataRow dr = dt.NewRow();
dr[0] = uid;
dr[1] = pid;
dt.Rows.Add(dr);
}
all the Best