简体   繁体   English

我怎样才能使gridview行可点击

[英]how can i make a gridview rows clickable

i have a gridview that i filled it with filenames from a path, know, i want the filenames to be clickable so i can download them and i don't know how, can someone help me. 我有一个gridview,我用路径中的文件名填充了它,知道,我希望文件名可单击,以便我可以下载它们,但我不知道如何,有人可以帮助我。 code-behind (file is the gridview ID) 后台代码(文件是gridview ID)

string path = "//the path";
string[] Fname = Directory.GetFiles(path).Select(Path.GetFileName).ToArray();
file.DataSource = Fname;
file.DataBind(); 

the web page 网页

<asp:GridView ID="file" runat="server" style="border:hidden" ></asp:GridView>

You can bind a single list/array item and get it in the ItemTemplate like this: 您可以绑定单个列表/数组项,并按以下方式在ItemTemplate获取它:

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <a target="_blank" href="<%# Container.DataItem %>">
                    <%# Container.DataItem %>
                </a>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
    <asp:HyperLink ID="UserId" runat="server" DataNavigateUrlFields="UserId" NavigateUrl='<%# "~/Report.aspx?name=" %>' 
                Text='<%# Eval("UserId") %>' ></asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>

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

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