gridview HyperLink 动态改变

1、首先在在gridview 的column 列新增一个HyperLink 列

                    <asp:TemplateField HeaderText="合同信息" >
                                 <ItemTemplate>
                   
                                <asp:HyperLink ID="HyperLink1"  runat="server"  ></asp:HyperLink> 
                        </ItemTemplate>
                               <HeaderStyle HorizontalAlign="Center" Width="50px" />
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:TemplateField>

2、在 GridView1_RowDataBound 事件中进行动态管理代码如下

数据库中增加一个state ,新增一个state列来判断是新增还是修改

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                if (drv.Row["ywhetong"].ToString() == "1")
                {
                    ((HyperLink)e.Row.Cells[5].FindControl("HyperLink1")).Text = "管理";
                    ((HyperLink)e.Row.Cells[5].FindControl("HyperLink1")).NavigateUrl = string.Format("hetongNowEdit.aspx?projectid={0}", drv.Row["projectid"].ToString());
                }

                else
                {
                    ((HyperLink)e.Row.Cells[5].FindControl("HyperLink1")).Text = "新建合同";
                    ((HyperLink)e.Row.Cells[5].FindControl("HyperLink1")).NavigateUrl = string.Format("hetongNewAdd.aspx?id={0}", drv.Row["id"].ToString());
                }

            }
           
        }

 

posted @ 2019-06-04 10:23  君莫笑~~  阅读(462)  评论(0编辑  收藏  举报