Hi,
I have a GridView containing all the information and data related to a table, the 'content' table.
I would like to know how to download files by pressing the 'Download' button presented in the GridView.
GridView1 RowCommand Code:
Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
If e.CommandName = "Download" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Dim contentID As Integer = Convert.ToInt32(GridView1.DataKeys(index).Value)
Dim strQuery As String = "SELECT content_name, content_type, content_file FROM content where content_id=@id"
Dim cmd As SqlCommand = New SqlCommand(strQuery)
cmd.Parameters.AddWithValue("@id", contentID)
Dim dt As DataTable = GetData(cmd)
If dt IsNot Nothing Then
download(dt)
End If
End If
End Sub
GridView1 Code:
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="content_id" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowSelectButton="True">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle BorderStyle="None" HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:CommandField>
<asp:BoundField DataField="content_id" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="content_id">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="30px" />
</asp:BoundField>
<asp:BoundField DataField="content_name" HeaderText="Name" SortExpression="content_name">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="content_type" HeaderText="Type" SortExpression="content_type">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:ButtonField ButtonType="Button" CommandName="Download" HeaderText="" Text="Download" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
SqlDataSource1 Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" DeleteCommand="DELETE FROM [content] WHERE [content_id] = @content_id" InsertCommand="INSERT INTO [content] ([content_name], [content_type]) VALUES (@content_name, @content_type)" SelectCommand="SELECT [content_name], [content_type], [content_id] FROM [content]" UpdateCommand="UPDATE [content] SET [content_name] = @content_name, [content_type] = @content_type WHERE [content_id] = @content_id">
<DeleteParameters>
<asp:Parameter Name="content_id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="content_name" Type="String" />
<asp:Parameter Name="content_type" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="content_name" Type="String" />
<asp:Parameter Name="content_type" Type="String" />
<asp:Parameter Name="content_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
Full Code: http://pastebin.com/W4kdwfPn[
^]
Whenever I click the 'Download' button, nothing happens.
Can anyone point me to the right direction?