如何动态修改GridView中HyperLinkField的NavigateUrl
1个回答
2016-09-09
展开全部
解决方案 »
在GridView的RowDataBound事件中:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//模板列
((HyperLink)e.Row.Cells[1].FindControl("HyperLink1")).NavigateUrl = "http://" + e.Row.Cells[1].Text + ".rar"; }
}若是非模板列:
((HyperLink)e.Row.Cells[1].Controls[0]).NavigateUrl = "http://" + e.Row.Cells[1].Text + ".rar";
还是不行的 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//模板列 ((HyperLink)e.Row.Cells[1].FindControl("HyperLink1")).NavigateUrl = "http://Documents/" + e.Row.Cells[1].Text + ".rar"; }
}<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DocumentID"
DataSourceID="SqlDataSource1" SkinID="GridView" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="DocumentID" HeaderText="DocumentID" InsertVisible="F
在GridView的RowDataBound事件中:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//模板列
((HyperLink)e.Row.Cells[1].FindControl("HyperLink1")).NavigateUrl = "http://" + e.Row.Cells[1].Text + ".rar"; }
}若是非模板列:
((HyperLink)e.Row.Cells[1].Controls[0]).NavigateUrl = "http://" + e.Row.Cells[1].Text + ".rar";
还是不行的 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//模板列 ((HyperLink)e.Row.Cells[1].FindControl("HyperLink1")).NavigateUrl = "http://Documents/" + e.Row.Cells[1].Text + ".rar"; }
}<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DocumentID"
DataSourceID="SqlDataSource1" SkinID="GridView" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="DocumentID" HeaderText="DocumentID" InsertVisible="F
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询