0

I am trying to use the id generated dynamically in asp.net.

<tr id="stdColTr" runat="server">
   <td style="font-size:10pt">
     <b>Nominal Tol(<asp:Label  id="lblStdSize_Unit" runat="server" Text=""></asp:Label>)</b>
   </td>
   <td>                   
      <asp:Label id="lblStdSize_Toler" runat="server" Text=""></asp:Label>                    
   </td>
</tr>

I have a label in uw.aspx and I am trying to bind the table in it and trying to check whether if value read from database is zero then that particular td should not be visible in that table.

uw.aspx.cs

lblStdSize_Toler.Text = "<table ><thead><tr><th colspan='2'>Diameter</th><th colspan='2'>Tolerance</th></tr></thead><tr><td id='STd1'>From</td><td id='STd2'>To</td><td id='STd3'>+</td><td id='STd4'>-</td></tr>";

while (ReadData.Read())
{
   prop_name = ReadData["prop_name"].ToString();
   t_property = ReadData["tprop"].ToString();
}
lblStdSize_Unit.Text = ReadData["WD_PROP"].ToString();                   
if (prop_name == "1sizMin")
{
   if (t_property=="0")
   {
      first td with id SD1 should be hidden.
   }

   lblStdSize_Toler.Text = lblStdSize_Toler.Text + "<td>" + tdc_property + "</td>";

 }

Similarly remaining td checked with t_property if value is "0" then it should be visible false.

Lewis86
  • 511
  • 6
  • 15
Mohan
  • 238
  • 2
  • 15

1 Answers1

0

If I understand you correctly this should do what you need. It creates a row per recordset returned an applies a style (visibility) to the first column (STd1). I don't know anything about the code environment and I also just added the code as I think it could work. Please adjust variable names or typos to your liking.

lblStdSize_Toler.Text = "<table ><thead><tr><th colspan='2'>Diameter</th><th colspan='2'>Tolerance</th></tr></thead>";

while (ReadData.Read())
{
   var row = "<tr><td id='STd1' style='visibility: {0};'>From</td><td id='STd2'>To</td><td id='STd3'>+</td><td id='STd4'>-</td></tr>";
   var visibility = "visible";

   prop_name = ReadData["prop_name"].ToString();
   t_property = ReadData["tprop"].ToString();

   lblStdSize_Unit.Text = ReadData["WD_PROP"].ToString();                   
   if (prop_name == "1sizMin")
   {
      if (t_property=="0")
      {
        visibility = "hidden";
      }
   }

   lblStdSize_Toler.Text += string.Format(row, visibility) + "<td>" + tdc_property + "</td>";
}