【问题标题】:how to use if condition in aspx page如何在aspx页面中使用if条件
【发布时间】:2014-05-22 04:53:14
【问题描述】:

我在执行时放置了带有条件的div,如果还显示了条件,我需要将其删除..

        **My New Code**

<asp:TemplateField HeaderStyle-Width="90px" ItemStyle-Width="0">
    <ItemTemplate>  

        <div style="cursor: pointer; padding-top: 02px;" onclick="ShowfllDetails(<%#Eval("StudentID")%>);">

        if(<%# (Eval("StatusName").Equals("Processed")) %>)
        {
            //should not show the upload button                   
        }
        else
        {
         <u>Upload </u> //show the upload button
        }
        </div>

        <asp:Image ID="Image1" runat="server" ImageUrl='<%#(Eval("StatusName").Equals("Processed") ? "images/add_btn.png" : "")%>' />

    </ItemTemplate>


我正在显示 if 条件我不需要显示它..

谢谢。

【问题讨论】:

  • 我不知道 jquery 你能建议我如何继承它..
  • 使用小提琴在此处发布您的 html jsfiddle.net

标签: c# asp.net gridview hyperlink


【解决方案1】:

我已经在 Gridview 中完成了这样的功能,我假设您也在这样做。代替标记,您可以使用链接按钮设置 commandArgument 和 Commandname 属性。之后触发 Gridview_Rowcommand 事件。当您单击链接按钮时,此事件将触发,您可以在数据库中或会话中的某处设置状态,即针对学生 ID 单击此链接

<asp:LinkButton ID="LinkButton1" runat="server" Text="Upload" CommandName="Upload"
                        CommandArgument='<%#Eval("StudentID")%>'></asp:LinkButton>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Upload")
    {
        // get student id against clicked link button
        int studentid = Convert.ToInt16(e.CommandArgument);
        // -- set status in database it is clicked
    }
}

在此之后绑定您的网格并在 rowdatabound 上找到控件并将可见性设置为 true 或 false(已处理/未处理)

将您的“StatusName”数据库字段绑定到标签,并将标签的可见性设置为 false,以便它不显示。

现在从下面的代码中获得灵感

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Display the company name in italics.
        Label lblAssignto = (Label)e.Row.FindControl("lblassignto");
        LinkButton addevent = (LinkButton)e.Row.FindControl("lnkBtnAddEvent");
        LinkButton showevent = (LinkButton)e.Row.FindControl("lnkBtnShowEvent");
        if (string.IsNullOrEmpty(lblAssignto.Text))
        {
            addevent.Visible = false;
            showevent.Visible = false;
        }
        else
        {
            addevent.Visible = true;
            showevent.Visible = true;
        }
    }
}

【讨论】:

  • 您不需要模板中的 if() 脚本,只需按照建议将代码转移到您的代码后面即可
  • 我想上传是一个“按钮”或“链接按钮”。您可以触发 gridview 的 rowdatabound,然后找到控件。根据“StatusName”你可以做到。
猜你喜欢
  • 1970-01-01
  • 2013-06-08
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多