Gridview with only one line - Asp.Net C#

Asked

Viewed 296 times

2

I have a column in Gridview with Schedules, I made a scheme that takes from such an hour to such an hour for example: 8:00 to 8:30 and so goes to other lines. In all, until 6:00, that’s 20 lines. How do I put this all in one line ? Something that would break down by "," and stay on the same line. Thank you.

  • You can change your data source, to own one item instead of several or change components, write a table.

  • I thought about owning only one item, but in this case it’s a list of times, would have problem anyway at the time to cut the hours like, I need to do this: 8:00 at 8:30, 8:30 at 9:00 and so it goes in one line only.

  • What if you foreach and concatenate the content into a string?

  • I tried to do this, only what type, I will assign to string the times I’m picking up in 2 objects like hora_start and hora_end and at the end add to ",". Only then when the list is finished the last comma will stay there ..

  • The last comma you take out, that’s simple, but my question would be: Why everything in a Row? I do not understand why, because in separate Row it is much more readable, unless there is a very specific rule, so the question, just for that reason.

  • A way to remove the last comma: Stringbuilder Sb = new Stringbuilder("1, 2, 3, "); string result = Sb.Tostring(0, Sb. Length - 2);

Show 1 more comment

1 answer

1

You can use the component Repeater to do this. The similar code would be:

<asp:Repeater ID="rptHorarios" runat="server">
   <HeaderTemplate>
      <table border="0" id="tblHorarios">
         <tr>
   </HeaderTemplate>

   <ItemTemplate>
        <td>Eval("Horario")</td>
   </ItemTemplate>
   <FotterTemplate>
        </tr>
      </table>
   </FotterTemplate>
</asp:Repeater>

Code:

public void Page_Load(object sender, EventArgs args)
{
   if (!IsPostBack)
   {
      rptHorarios.DataSource = GetHorarios();
      rptHorarios.DataBind();
   }
}

Or you could also use the Datalist and set the properties Repeatdirection and Repeatcolumn with their respective values.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.