简体   繁体   English

真正简单的GridView ASP.NET问题

[英]Really simple GridView ASP.NET question

Ok, this should be really easy, but I just don't have enough experience. 好的,这确实很容易,但是我只是没有足够的经验。

I need to throw a GridView on a WebForm and populate with a List, where Template is my class that has ID, Name, CreatedOn, etc... properties. 我需要在WebForm上抛出一个GridView并填充一个List,其中Template是我的具有ID,Name,CreatedOn等属性的类。

The GridView needs to display each Template Name as a link. GridView需要将每个模板名称显示为链接。 The link should point to TemplateEdit.aspx page, with the following URL: TemplateEdit.aspx?ID={ID of Template}. 该链接应指向具有以下URL的TemplateEdit.aspx页面:TemplateEdit.aspx?ID = {模板ID}。

I also need a Delete link (preferably an image link), that should popup a Yes/No delete confirmation dialog. 我还需要一个“删除”链接(最好是一个图像链接),该链接会弹出“是/否”删除确认对话框。

I've actually done this before in 2005 or so, but I simply can't remember anymore. 实际上,我在2005年左右之前就已经做到了,但是我已经不记得了。

Here's how you do it (borrowed the code from here to save some typing) 这是您的操作方法(从此处借用代码以节省一些输入内容)

<asp:TemplateField HeaderText="Statement" SortExpression="Statement">
  <ItemTemplate>
    <asp:HyperLink ID="Link1" runat="server" NavigateUrl='<%# Bind("ID", "~/TemplateEdit.aspx?ID={0}") %>' Text="The Best Link"></asp:HyperLink  >
  </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
  <ItemTemplate>
    <asp:ImageButton ID="DeleteButton" Runat="server" ImageUrl="~/images/delete.gif" OnClientClick="return confirm('Are you sure you want to delete this?');" ToolTip="Delete" CommandName="Delete" />
    </ItemTemplate>
</asp:TemplateField>

didn't actually test it, but looks like it should work. 并没有实际测试,但看起来应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM