在gridview中有一个hyperlink,提供取消任务的连接。
因为同一任务只能取消一次,所以点击一次后希将hyperlink隐藏(或禁用)。怎样实现这个功能(.NET/C#)?
知道的朋友请尽快给与指点  

解决方案 »

  1.   

    本帖最后由 net_lover 于 2012-03-01 16:17:44 编辑
      

  2.   

    我是想用这种方法:
    帮我看看条件语句里面的内容要怎么写
    下面代码中的"CancelTask"是hyperLink的id//事件代码
    protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (gvTecherIndex.DataKeys[e.Row.RowIndex][0] == "1")//这句是有错的
    {
        e.Row.FindControl("CancelTask").Visible = false;
    }
    else
    {
        e.Row.FindControl("CancelTask").Visible = true;
    }
           }
    //.......................................................
    <asp:GridView ID="gvTecherIndex" runat="server" AutoGenerateColumns="False" Width="658px" 
                        style="margin-left: 0px" AllowPaging="True" 
                        onpageindexchanging="gvTecherIndex_PageIndexChanging" 
                        onrowdatabound="gvTecherIndex_RowDataBound" 
                        onselectedindexchanged="gvTecherIndex_SelectedIndexChanged">
                        <Columns>
                            <asp:BoundField DataField="Q_id" HeaderText="题目编号" Visible="False" />
                            <asp:HyperLinkField DataNavigateUrlFields="Q_id" 
                                DataNavigateUrlFormatString="teacher_details.aspx?Q_id={0}" 
                                HeaderText="题目" DataTextField="Q_title" />
                            <asp:BoundField DataField="Q_createtime" HeaderText="布置时间"></asp:BoundField>
                            <asp:BoundField DataField="Q_finishtime" HeaderText="要求完成时间"></asp:BoundField>
                            <asp:BoundField DataField="stu_id" HeaderText="学号" Visible="False" />
                            <asp:TemplateField HeaderText="传递到本页">
                                <ItemTemplate>
                                    <asp:HyperLink ID="CancelTask" runat="server" 
                                        NavigateUrl='<%# Eval("Q_id", "teacher_Index.aspx?Q_id={0}") %>' Text="取消作业"></asp:HyperLink>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerSettings FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" 
                            PreviousPageText="上一页" Mode="NextPreviousFirstLast" />
                    </asp:GridView>
      

  3.   

    改成
    if (e.Row.RowType == DataControlRowType.DataRow)
      

  4.   

    //那就是这样子的:  现在主要是判断hyperlin是否被点击过,如果点击过就隐藏             
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        if (gvTecherIndex.DataKeys[e.Row.RowIndex][0] == "0")//在在这里要判断hpylink有没有被点击过
         {
         e.Row.FindControl("CancelTask").Visible = false;
         //e.Row.Cells[0].Text = "被取消";     }
       else
          {
           //e.Row.FindControl("CancelTask").Visible = true;
          }
    }