导航

Gridview上顯示HyperLink

Posted on 2010-02-09 09:49  杨彬Allen  阅读(165)  评论(0)    收藏  举报
方法一:在html端直接綁定參數。
  優點:簡單。
  缺點:參數值暴露在url中,不安全。
<asp:TemplateField HeaderText="QID">
    <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" runat="server" Style=" position:relative"  Text='<%# Eval("QID") %>' NavigateUrl='<%# Eval("QID","Modification2.aspx?QID={0}") %>'></asp:HyperLink>
    </ItemTemplate>
 </asp:TemplateField>
                         

 方法二:在GridView_RowDataBound中綁定參數

    優點:可以調用JS。

    缺點:將參數暴露在url中,不安全。   

代码
//绑定链接
protected void CPSGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string plant = string.Empty;
string sloc = string.Empty;
string material = string.Empty;
string mvt = string.Empty;
string inorout = string.Empty;
if (e.Row.RowType == DataControlRowType.DataRow)
{
plant
= e.Row.Cells[1].Text.Trim();
sloc
= e.Row.Cells[2].Text.Trim();
material
= e.Row.Cells[3].Text.Trim();
mvt
= e.Row.Cells[6].Text.Trim();
inorout
= e.Row.Cells[8].Text.Trim();
e.Row.Cells[
3].Text = "<a href=\"javascript:OpenPage('" + plant + "','" + sloc + "','" + material + "','" + mvt + "','" + inorout + "')\">" + material + "</a>";
}
//FrozenColumn();
}