如何根据一定的条件在网格视图中添加动态超级链接 [英] How to add dynamic hyperlink in Grid View according to certain condition

查看:118
本文介绍了如何根据一定的条件在网格视图中添加动态超级链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站,我目前使用从3个表即状态,Project_glance,Application_header生成数据的网格视图。 SQL查询返回4列,但在我的网格视图我只显示3列。最后一列返回继project.The的STATUS_ID是我的.aspx code:

In my Website, I currently use a grid view which generates data from 3 tables namely status, Project_glance, Application_header. SQL Query returns 4 columns but in my grid-view i only shows 3 columns. The last column returns the Status_id of the project.The following is my .aspx code:

<asp:GridView ID="grdProf" runat="server" AllowPaging="True"   AutoGenerateColumns="false" OnPageIndexChanging="grdProf_PageIndexChanging">
<Columns>
  <asp:TemplateField>
        <ItemTemplate>
           <asp:HyperLink ID="hlnkView" Visible="true" Text="View" runat="server" >     </asp:HyperLink>
        </ItemTemplate>
  </asp:TemplateField>
  <asp:BoundField DataField="ApplicationID" HeaderText="ApplicantionID" />
  <asp:BoundField DataField="PRGLProjectTitle" HeaderText="Project Title" />
  <asp:BoundField DataField="Status" HeaderText="Project Status" />
</Columns>
</asp:GridView>

如果该STATUS_ID> 15则只能查看超链接将可见,否则查看超链接文本将被更改为编辑和导航URL将添加到该超链接,另一个超级链接删除将显示允许用户删除项目详细信息。

If the Status_id > 15 then only view hyperlink will visible otherwise the View hyperlink text will be changed to 'Edit' and a navigate URL will add to this hyperlink and another hyperlink 'Delete' will show to allow user to delete the project detail.

请帮我找到这个正确的解决方案。

Please help me to find the correct solution for this..

推荐答案

筛选

protected void grdProf_RowDataBound(Object sender, GridViewRowEventArgs e)
{

 if(e.Row.RowType == DataControlRowType.DataRow)
 {

   DataRowView rowView = (DataRowView)e.Row.DataItem;

   // Retrieve the status value for the current row. 
   string status = rowView["Status"].ToString();
   //Now you have the status 
   //get a reference to view hyperlink and hide it if that's the case
   Hyperlink hlnkView = e.Row.FindControl("hlnkView") as HyperLink;
   //example: 
   if(int.Parse(status)>15)
      hlnkView .Visible=false;//you are done

 }
}

至于显示一个编辑超链接,我将有一个额外的列旁边的查看栏和隐藏或在必要时显示该超链接等,因为在某些情况下,你需要一个超链接列,并在某些情况下你需要两个。

As far as displaying an "edit" hyperlink, I would have an extra column next to the "view" column and hide or display this other hyperlink as necessary since in some cases you'll need one hyperlink column and in some cases you'll need two.

这篇关于如何根据一定的条件在网格视图中添加动态超级链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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