how to get the number of hits clicked by the Download Button

Posted by Ptharak under C# on 5/9/2011 | Points: 10 | Views : 1148 | Status : [Member] | Replies : 1

Here I need to count number of hits done by user for particular attachement column

how to get the number of hits clicked by the Download Button

This is my Gridview Design

<asp:GridView ID="KMGridView" runat="server" GridLines="None" AutoGenerateColumns="false" DataKeyNames="Category">
<asp:BoundField HeaderText="Category" DataField="Category" />
<asp:BoundField HeaderText="SubCategory" DataField="SubCategory" />
<asp:BoundField HeaderText="FileName" DataField="Filename" />
<asp:BoundField HeaderText="Author" DataField="Author" />
<asp:BoundField HeaderText="CreationDate" DataField="CreationDate" />
<asp:BoundField HeaderText="UploadedBy" DataField="UploadedBy" />
<asp:BoundField HeaderText="UploadDate" DataField="UploadedDate" />
<asp:BoundField HeaderText="Hits" DataField="Hits" />
<asp:BoundField HeaderText="Mail" DataField="Mail" />
<asp:BoundField HeaderText="Download" DataField="Download" />

Can u say now , what should I do for gets NumberOfHits

Thanks & Regards


Posted by: Ndebata on: 5/10/2011 [Member] Starter | Points: 25

Instead of BoundField Column add a Template Field as bellow

<asp:Button ID="btnDownload" runat="server" Text="Button" OnClick="dwn_click" />

Then in page code behind file

public void dwn_click(object sender, EventArgs e)
GridViewRow selectedRow = ((Control)sender).Parent.NamingContainer as GridViewRow;
//in column index 7 you are showing hits
selectedRow.Cells[7].Text = (Convert.ToInt64(selectedRow.Cells[7].Text) + 1).ToString();
//save it to database

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

Login to post response