本文介绍了如何使用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..

推荐答案


<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超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:22
查看更多