| |

VerySource

 Forgot password?
 Register
Search
View: 686|Reply: 3

I want to implement a judgment statement when binding data, I do n’t know how to write the code

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-7 10:30:01
| Show all posts |Read mode
The binding code is as follows:
<% # DataBinder.Eval (Container.DataItem, "adminRestore")%>

How to implement the function like below?
<% if (userpopedom.Trim () == "all" || userpopedom.Trim () == "newseditor") {%>
<tr height = "20"> <td>
&nbsp; <a href="admins/admin_addnews.aspx" target="right"> Add News </a> | <a href="admins/admin_managenews.aspx" target="right"> News Management </a> < / td>
</ tr>
<%}%>

That is, use an if statement to determine whether the length of <% # DataBinder.Eval (Container.DataItem, "adminRestore")%> is 0 to determine whether to display a certain piece of code.
Reply

Use magic Report

0

Threads

43

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-1-7 12:24:02
| Show all posts
UP
Also want to know the answer
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-7 17:27:01
| Show all posts
method 1 :
<% # (DataBinder.Eval (Container.DataItem, "adminRestore") == "1")? Result 1: Result 2%>

Method 2:
Write a function
Public string YourFunc (object str) {
if (str == "1") {
return result 1;
} else {
return result 2;
}
}

<% # YourFunc (DataBinder.Eval (Container.DataItem, "adminRestore"))%>
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-7 17:54:02
| Show all posts
method 1 :
<% # (DataBinder.Eval (Container.DataItem, "adminRestore"). ToString (). Length == 0)? Result 1: Result 2%>

Method 2:
Write a function
Public string YourFunc (object str) {
if (str.ToString (). Length == 0) {
return result 1; // not displayed
} else {
return result 2; // show
}
}

<% # YourFunc (DataBinder.Eval (Container.DataItem, "adminRestore"))%>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list