Click here to Skip to main content
15,891,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
*.aspx

XML
<asp:templatefield HeaderText="Value">
    <itemtemplate>
        <asp:CheckBox ID="ckbValue" runat="server" Checked='<%# Eval("szValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szValue")) || Eval("szDefaultValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szDefaultValue"))%>' CssClass="pkchkbox" ></asp:CheckBox>
    </itemtemplate>
</asp:templatefield>


*.aspx.cs
C#
foreach (DataRow row in m_dt.Rows)
          {
              if (row[1].ToString() == "Y")
              {
                  row[1] = true;
                                  }
              else if (row[1].ToString() == "N")
                  row[1] = false;
          }


I wan to convert szValue and szDefaultValue that will display in one checkbox.
But it's not work.
Help me to solve my problem. thankyou
Posted
Comments
Kornfeld Eliyahu Peter 15-Dec-14 3:40am    
Please elaborate on 'it's not work' - what? where?
Member 10889447 15-Dec-14 3:47am    
<asp:CheckBox ID="ckbValue" runat="server" Checked='<%# Eval("szValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szValue")) || Eval("szDefaultValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szDefaultValue"))%>' CssClass="pkchkbox" >

This convert not work.
I want to convert szValue and szDefaultValue.
Kornfeld Eliyahu Peter 15-Dec-14 3:49am    
What not work? You got error? You got μ instead of true or false? What?
Member 10889447 15-Dec-14 3:52am    
nothing error. but can't convert string to boolean. Yeah i want got true or false from szValue or szDefaultValue.
Kornfeld Eliyahu Peter 15-Dec-14 4:08am    
What the actual value of those strings?

Quote:
But it's not work

That's not pretty informative. You should detail.

Your code is not robust, possibly you need to handle null values, possibly you have to trim the retrieved string, possibly you have to handle both "Y", "N" and everything else.
 
Share this answer
 
Comments
Member 10889447 15-Dec-14 3:48am    
<asp:CheckBox ID="ckbValue" runat="server" Checked='<%# Eval("szValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szValue")) || Eval("szDefaultValue") == DBNull.Value ? false : Convert.ToBoolean(Eval("szDefaultValue"))%>' CssClass="pkchkbox" >

that is not work, can't to convert.
Convert.ToBoolean can not interpret any string - in fact it uses Boolean.Parse which have 'True' and 'False' as strings to interpret (case-insensitive)...
To convert other strings to Boolean you have to write your own code...One option is
C#
bool bVal = "Y".Equals(orgValue, StringComparison.OrdinalIgnoreCase);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900