Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have One Grid View with Access 2003 Database.

I have Two Columns in Grid View with Databound.

1) Id / Name
2) Click Here Button

For Every Button of Click Here required Event Code like
Response.Redirect("~/pdf/daasi.pdf")
or
~/pdf/daasi.pdf
saved in Database.
Now I want to Run Saved Response.Redirect Code when user click on button of gridview.
Note : Each Button has Diffrent Redirect Code Saved in Database. e.g. ~/pdf/Daasi.pdf
VB
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="AccessDataSource1" Width="236px" Font-Names="Calibri">
            <columns>
                <asp:BoundField DataField="Id" HeaderText="Id" 
                    SortExpression="Id" />
                <asp:ImageField DataImageUrlField="ImageUrl" HeaderText="Image Url">
                
                <asp:BoundField DataField="NameofBook" HeaderText="Name of Book" 
                    SortExpression="NameofBook" />
                <asp:ButtonField ButtonType="Button" DataTextField="ViewLink" 
                    DataTextFormatString="Read Now" SortExpression="ViewLink" Text="Button1" />
                <asp:ButtonField ButtonType="Button" DataTextField="DownloadLink" 
                    DataTextFormatString="Download" SortExpression="DownloadLink" Text="Button2" />
            </columns>
            <emptydatatemplate>
                ImageUrl
            </emptydatatemplate>
Posted
Updated 13-May-12 19:33pm
v9

if your buttons asp.net buttons add this attribute to your button
C#
PostBackUrl='<%# "~/" + Eval("saved_postback_url")%>'
 
Share this answer
 
v2
Comments
s1a2b3 11-May-12 5:13am    
Url Code already stored in Database , How to Add same code from database?
Dain Ucak 11-May-12 5:14am    
whats your column name in database which stored url code
s1a2b3 11-May-12 5:21am    
In "Test" Table Column Name "ViewUrl" (~/pdf/test.pdf)
Dain Ucak 11-May-12 5:47am    
make that
PostBackUrl='<%# Eval("ViewUrl")%>'
bind your column of url to your buttons postbackurl. if you can share your codes i can help you more.
s1a2b3 11-May-12 6:24am    
Where to Pass Said Code?
hi replace your gridview html with the following. I have added a template field

ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
      Width="236px" Font-Names="Calibri">
      <Columns>
          <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
          <asp:ImageField DataImageUrlField="ImageUrl" HeaderText="Image Url">
          </asp:ImageField>
          <asp:BoundField DataField="NameofBook" HeaderText="Name of Book" SortExpression="NameofBook" />
          <asp:TemplateField HeaderText="View Link">
              <ItemTemplate>
                  <asp:LinkButton ID="lnkViewLink" runat="server" PostBackUrl='<%#  Eval("ViewUrl")%>' Text="View Link"></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>
          <asp:ButtonField ButtonType="Button" DataTextField="DownloadLink" DataTextFormatString="Download"
              SortExpression="DownloadLink" Text="Button2" />
      </Columns>
      <EmptyDataTemplate>
          ImageUrl
      </EmptyDataTemplate>
  </asp:GridView>

important thing is that your stored link should be a relative link otherwise it will break.
 
Share this answer
 
v2
Comments
s1a2b3 11-May-12 6:50am    
The server tag is not well formed.
on <asp:linkbutton id="lnkViewLink" runat="server" postbackurl="<%# Eval("ViewUrl")%>">
Text="View Link">
tanweer 11-May-12 6:52am    
i have just edited the code please replace it again
s1a2b3 11-May-12 7:30am    
The HTTP verb POST used to access path '/pdf/Daasi.pdf' is not allowed
tanweer 11-May-12 7:55am    
as I said early that your stored link should be relative, it should look like ~/pdf/test.pdf.
s1a2b3 14-May-12 1:10am    
I also tried as you write but same error displayed.

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