简体   繁体   中英

how to use if condition in aspx page

I had placed div with condition.. on my execution,if condition is also displayed, i need to remove it..

        **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>

在此处输入图片说明
I'm getting displayed the if condition i need not to display it..

Thank-You.

I have done such a functionality inside Gridview, I assume you are doing the same. In place of tag you can use linkbutton set commandArgument and Commandname properties. AFter that fire Gridview_Rowcommand event. when ever you will click on linkbutton this event will fire and you can set the status in database or somewhere in session that this link is clicked against student 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
    }
}

after this bind your grid and on rowdatabound find control and set the visibility to true or false (Processed/Not Processed)

Bind your "StatusName" database field to a label and set the visibility to false of Label so that it should not display.

Now take idea from following code

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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM