Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following View in my Web Application. I am unable to use the rowspan properly. I can't find what property I am missing to get the row in the third column to split into the number based on the count.

My count has the exact number of properties. only two rows are rendered properly and the last one is not rendered. I have also tried using @: . But nothing worked.

View

HTML
@foreach (var item in Model.OptionValues)
    {            
      <tr>
        <td rowspan="@item.SetValue.Count" >@item.OptionVal</td>
        <td rowspan="@item.SetValue.Count">@item.OptionValueID</td>
        @{var set = item.SetValue.FirstOrDefault(x => x.OptionValueID == item.OptionValueID);}
        @if (set != null)
        {
            for (int i = 0; i < item.SetValue.Count; i++)
            {
               <tr>
                  <td>@set.TcSet.SetName</td>
                  <td> @set.Value</td>
                  <td>@set.Status</td>
               </tr>
            }

        }
      </tr>
    }



I am not getting all the rows rendered properly in a single column. the last row is shown along with the main table.
Posted
Comments
[no name] 8-Oct-15 11:00am    
Firstly @item.SetValue.Count has correct value?

Secondly as per your logic whatever HTML code is generating, please deeply look into that. Make sure that HTML code is properly generated. If you have any doubt please provide what your HTML code generating with code.
vini vasundharan 9-Oct-15 1:38am    
i have already checked if count has the right value. It has the right value. The code doesnt display the results as required. the logic in the HTML block is wrong but it is right to generate a table with rowspan


You're generating invalid HTML - you can't nest a <tr> inside another <tr>.

Try something like this instead:
HTML
@foreach (var item in Model.OptionValues)
{            
    <tr>
        <td rowspan="@item.SetValue.Count" >@item.OptionVal</td>
        <td rowspan="@item.SetValue.Count">@item.OptionValueID</td>
		
        @{var set = item.SetValue.FirstOrDefault(x => x.OptionValueID == item.OptionValueID);}
		
        @if (set != null)
        {
            <td>@set.TcSet.SetName</td>
            <td> @set.Value</td>
            <td>@set.Status</td>
			
            for (int i = 1; i < item.SetValue.Count; i++)
            {
                </tr>
                <tr>
                    <td>@set.TcSet.SetName</td>
                    <td> @set.Value</td>
                    <td>@set.Status</td>
            }
        }
    </tr>
}
 
Share this answer
 
Comments
vini vasundharan 9-Oct-15 1:41am    
hello Richard.
Thanks for your reply. I also added a if else statement to get it working because i else i got the same reply like i had before.
I am not sure if the If else approach is a right way of doing. Posting what I got
HTML
@foreach (var item in Model.OptionValues)
        {
            //var row = @item.SetValue.Count + 1;

            @:<table><tbody><tr>
                @:<td rowspan="@item.SetValue.Count">@item.OptionVal</td>
                @:<td rowspan="@item.SetValue.Count">@item.OptionValueID</td>
                var set = item.SetValue.FirstOrDefault(x => x.OptionValueID == item.OptionValueID);
                if (set != null)
                {

                    for (int i = 0; i < item.SetValue.Count; i++)
                    {
                        if (i == 0)
                            {
                                @:<td>@set.TcSet.SetName</td>
                                @:<td> @set.Value</td>
                                @:<td>@set.Status</td>
                                @:</tr></tbody></table>
                            }

                            else
                            {

                            
                                @:<tr>
                                @:<td>@set.TcSet.SetName</td>
                                @:<td> @set.Value</td>
                                @:<td>@set.Status</td>
                           
                        

                    }

                }
             @:</tr>
        }


I did it this way to get it right. Any other better approach to get it right?
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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