Answered by:
fixed repeater row size

Question
-
User1717218719 posted
Hi All
I am using a repeater in which I have a table. at present if only one row of data is being read in the table displays space for only 1 row. I would like to have it fixed to 4 rows in size even if less than 4 are being filled. how would I go about this in asp.net vb ?
any help would be great
Monday, August 19, 2019 11:14 AM
Answers
-
User288213138 posted
Hi E.RU,
According to your description, I made a demo for your reference.
When the data from the database is populated into the DataTable, new rows are added based on the number of rows in the DataTable.
The code:
<asp:Repeater ID = "Repeater1" runat="server"> <HeaderTemplate> <table border = "0" > < tr > < th > Id </ th > </ tr > </ HeaderTemplate > < ItemTemplate > < tr > < td > < asp:TextBox ID = "TextBox1" runat="server" Text='<%# Eval("CustomerId") %>'></asp:TextBox> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> Public Sub Bind() Using con As SqlConnection = New SqlConnection(str) Dim sql As String = "Select * from Customer" Using adapter As SqlDataAdapter = New SqlDataAdapter(sql, con) Dim dt As DataTable = New DataTable() adapter.Fill(dt) Dim a As Integer = dt.Rows.Count For i As Integer = 1 To 4 - a Dim dr As DataRow = dt.NewRow() dt.Rows.Add(dr) Next Repeater1.DataSource = dt Repeater1.DataBind() End Using End Using End Sub
The result:
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 20, 2019 7:10 AM
All replies
-
User475983607 posted
Hi All
I am using a repeater in which I have a table. at present if only one row of data is being read in the table displays space for only 1 row. I would like to have it fixed to 4 rows in size even if less than 4 are being filled. how would I go about this in asp.net vb ?
any help would be great
It's difficult to answer without source code. I assume all you have to do is check the DataTable row count and add empty records until there are 4. Then bind the Repeater to the DataTable.
Monday, August 19, 2019 11:22 AM -
User1717218719 posted
Here is an example of my source code. the table is being filled in from an sql database
<asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate> <table style="width: 100%"> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="txtX" runat="server" ReadOnly="true" Text='<%#Eval("X") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="Y" runat="server" ReadOnly="true" Text='<%#Eval("Y") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="Z" runat="server" ReadOnly="true" Text='<%#Eval("Z").ToString() %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="A" runat="server" ReadOnly="true" Text='<%#Eval("A").ToString() %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="B" runat="server" ReadOnly="true" Text='<%#Eval("B") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="C" runat="server" ReadOnly="true" Text='<%#Eval("C") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="D" runat="server" ReadOnly="true" Text='<%#Eval("D") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="E" runat="server" ReadOnly="true" Text='<%#Eval("E") %>'></asp:TextBox></td> <td style="border-bottom-color: transparent"> <asp:TextBox CssClass="lbl" ID="F" runat="server" ReadOnly="true" Text='<%#Eval("F") %>'></asp:TextBox></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
Thank you for your reply mgebhard. How would I go about that? thanks
Monday, August 19, 2019 11:45 AM -
User475983607 posted
You did not post the most important bit of code which is your data access layer. Again, simply check the result set for the record count. If there are less then 4 then add records to the object you are using to bind to the repeater.
Monday, August 19, 2019 12:47 PM -
User1717218719 posted
here is the other part of my code
Me.Repeater1.DataSource = argDst.Tables("tbl") Me.Repeater1.DataBind()
argDst is a dataset
I am unsure as to how to code that could u provide an example
Monday, August 19, 2019 2:16 PM -
User475983607 posted
I am unsure as to how to code that could u provide an exampleThe official DataTable documentation explains how to add a row.
https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.newrow?view=netframework-4.8
You can get the row count form the DataTable.Rows property.
https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.rows?view=netframework-4.8
Monday, August 19, 2019 5:51 PM -
User288213138 posted
Hi E.RU,
According to your description, I made a demo for your reference.
When the data from the database is populated into the DataTable, new rows are added based on the number of rows in the DataTable.
The code:
<asp:Repeater ID = "Repeater1" runat="server"> <HeaderTemplate> <table border = "0" > < tr > < th > Id </ th > </ tr > </ HeaderTemplate > < ItemTemplate > < tr > < td > < asp:TextBox ID = "TextBox1" runat="server" Text='<%# Eval("CustomerId") %>'></asp:TextBox> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> Public Sub Bind() Using con As SqlConnection = New SqlConnection(str) Dim sql As String = "Select * from Customer" Using adapter As SqlDataAdapter = New SqlDataAdapter(sql, con) Dim dt As DataTable = New DataTable() adapter.Fill(dt) Dim a As Integer = dt.Rows.Count For i As Integer = 1 To 4 - a Dim dr As DataRow = dt.NewRow() dt.Rows.Add(dr) Next Repeater1.DataSource = dt Repeater1.DataBind() End Using End Using End Sub
The result:
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 20, 2019 7:10 AM