按钮单击Gridview中的代码?
问题描述:
我在Access 2003数据库中拥有一个网格视图.
我在具有数据绑定的网格视图中有两列.
1)ID/名称
2)单击此处按钮
对于单击此处的每个按钮",必需的事件代码(如
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")
或
~/pdf/daasi.pdf
)保存在数据库中.
现在,我想在用户单击gridview的按钮时运行保存的Response.Redirect代码".
注意:每个按钮在数据库中都有不同的重定向代码.例如〜/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
<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>
答
如果您的按钮asp.net按钮将此属性添加到您的按钮中
if your buttons asp.net buttons add this attribute to your button
PostBackUrl='<%# "~/" + Eval("saved_postback_url")%>'
嗨 将您的gridview html替换为以下内容.我添加了一个模板字段
hi replace your gridview html with the following. I have added a template field
<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.