如何使用GridView超链接? [英] How to use gridview hyperlink?

查看:103
本文介绍了如何使用GridView超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了mysql数据库,它有一个名为data的表,该数据有两个列标题和链接

我想使用gridview这个网格加载WTITH标题,然后单击gridview上的标题,这将成为链接或其他页面

该怎么做

我会使用超链接吗?

请一个人明确地说谢谢..

I used mysql database this has a table called data this data has two column title and link

I want to use a gridview this grid load WİTH title and I will click the title on the gridview this will goes link or another page

how to do that

I will use hyperlink?

Please by one by clearly say that thank you..

推荐答案

您是否考虑过买书?是的,超链接实际上是HTML页面中链接到另一个页面的唯一方法.因此,您不应使用mysql,表或网格,而应阅读入门书籍.
Have you considered buying a book ? Yes, a hyperlink is literally the only way, in HTML, for your page to link to another page. As such, you should not be working with mysql, or tables, or grids, you should be reading beginner books.


亲爱的尝试一下:

Dear Try this:

<Columns>


     <asp:TemplateField HeaderText="Path" Visible="false">
     <ItemTemplate>
         <asp:Label ID="Label1" runat="server" Text='<%#Eval("document_link")%>' ></asp:Label>
     </ItemTemplate>
     </asp:TemplateField>



     <asp:TemplateField HeaderText="Title">
     <ItemTemplate>
         <asp:Label ID="Label2" runat="server" Text='<%#Eval("title")%>' Visible="false"></asp:Label>
         <asp:LinkButton ID="link1" runat="server"  CommandName="link" ForeColor="Blue" ToolTip='<%# String.Format("Uploaded on :{0}", Eval("time_of_attachment"))%>'> <%#Eval("title")%></asp:LinkButton>
     </ItemTemplate>

         <ItemStyle ForeColor="Blue" Font-Size="Medium"  />

     </asp:TemplateField>


     </Columns>




使用RowCreated的网格事件..




use Event of Grid of RowCreated..

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         var LinkButton2 = (LinkButton)e.Row.FindControl("link1");
         LinkButton2.CommandArgument = e.Row.RowIndex.ToString();
     }
 }



现在使用:



Now Use:

  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
        if(e.CommandName.Equals("link"))
        {
            try
            {
                int index = System.Convert.ToInt32(e.CommandArgument);
                LinkButton link_button =(LinkButton)GridView1.Rows[index].FindControl("link1");
                Label l1 = (Label)GridView1.Rows[index].FindControl("Label1");
                Label title = (Label)GridView1.Rows[index].FindControl("Label2");
Response.Redirect(l1.Text);

            }
        }
}


This will help you, if not Please tell me....


这篇关于如何使用GridView超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆