Link to home
Start Free TrialLog in
Avatar of JDL129
JDL129

asked on

Help with C# data repeater

Hey guys!!

I have some forms on which I need to display multiple rows of multiline data.  I will also need to add and delete rows.  What is the best way to do this and how would I go about it?

Thanks,

Jerry
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

That depends upon the amount of rows that you anticipate. If you have for example less than 25, I use a repeater. If the dataset will be large, I use gridviews.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx

Here is a nice MSDN about repeaters:
http://msdn.microsoft.com/en-us/magazine/cc163780.aspx

Gridviews natively allow sorting, paging, editing, and deleting. You can do all of those things in a repeater, but you have to create manual methods to handle each one in my experience.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx
Avatar of JDL129
JDL129

ASKER

jmiller1979!!!!

Thanks for the post!!!!  Unfortunately I'm going to need some code because those links are just greek to me.  I'm a newbie at this!!

Sorry,

Jerry
Here is a basic repeater:
<asp:Repeater id="repeater1" runat="server" >

        <HeaderTemplate>
        <table border="0" width="100%" class="style1">
        <tr style="background-color:#DCEDE5;">
            <th></th>
            <th>Name</th>
            </tr>
        </HeaderTemplate>

        <ItemTemplate>
        <tr bgcolor="#ffffff">
            <td>
           <asp:Label ID="lblID" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Container.DataItem("id"))%>' Visible="false"/>
           <asp:Button ID="btnDelete" runat="server" CommandName="delete" CssClass="button" Text="Delete" CausesValidation="false"/>
           <td><asp:Label ID="lblAccountName" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Container.DataItem("name"))%>'/>
           <asp:TextBox ID="txtName" runat="server" Visible="false" CssClass="textRepeaterEditWide" /></td>
           
                       
           </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
        <tr bgcolor="#e8e8e8">
            <td>
           <asp:Label ID="lblID" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Container.DataItem("id"))%>' Visible="false"/>
           <asp:Button ID="btnDelete" runat="server" CommandName="delete" CssClass="button" Text="Delete" CausesValidation="false"/><br />
           <td><asp:Label ID="lblAccountName" runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Container.DataItem("name"))%>'/></td>
           <asp:TextBox ID="txtName" runat="server" Visible="false" CssClass="textRepeaterEditWide" /></td>
         
         </tr>
        </AlternatingItemTemplate>      
        <FooterTemplate>
        </table>
        </FooterTemplate>

    </asp:Repeater>
And a gridview example:
 <asp:SqlDataSource ID="productsDataSource"
             Runat="server"
             SelectCommand="SELECT [ProductID], [ProductName],
               [QuantityPerUnit], [UnitPrice], [UnitsInStock] FROM
               [Products]"
         ConnectionString="<%$ ConnectionStrings:NWConnectionString %>"
         DataSourceMode="DataReader">
        </asp:SqlDataSource>
        <asp:GridView ID="productGridView" Runat="server"
          DataSourceID="productsDataSource"
            DataKeyNames="ProductID" AutoGenerateColumns="False"
             BorderWidth="1px" BackColor="#DEBA84"
             CellPadding="3" CellSpacing="2" BorderStyle="None"
             BorderColor="#DEBA84">
            <FooterStyle ForeColor="#8C4510"
              BackColor="#F7DFB5"></FooterStyle>
            <PagerStyle ForeColor="#8C4510"
              HorizontalAlign="Center"></PagerStyle>
            <HeaderStyle ForeColor="White" Font-Bold="True"
              BackColor="#A55129"></HeaderStyle>
            <Columns>
                <asp:BoundField ReadOnly="True" HeaderText="ID"
                  InsertVisible="False" DataField="ProductID"
                    SortExpression="ProductID">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Name"
                 DataField="ProductName"
                 SortExpression="ProductName"></asp:BoundField>
                <asp:BoundField HeaderText="Qty/Unit"
                 DataField="QuantityPerUnit"
                 SortExpression="QuantityPerUnit"></asp:BoundField>
                <asp:BoundField HeaderText="Price/Unit"
                DataField="UnitPrice" SortExpression="UnitPrice"
                DataFormatString="{0:c}">
                    <ItemStyle HorizontalAlign="Right"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField HeaderText="Units In Stock"
                  DataField="UnitsInStock"
                  SortExpression="UnitsInStock"
                   DataFormatString="{0:d}">
                    <ItemStyle HorizontalAlign="Right"></ItemStyle>
                </asp:BoundField>
            </Columns>
            <SelectedRowStyle ForeColor="White" Font-Bold="True"
             BackColor="#738A9C"></SelectedRowStyle>
            <RowStyle ForeColor="#8C4510"
               BackColor="#FFF7E7"></RowStyle>
        </asp:GridView>
Avatar of JDL129

ASKER

jmiller1979!!!!!  Thanks for the post!!!!!

Should this work in a windows form app?  I pasted the code in a form load event and it shows 92 errors.  I added using System.Xml.Schema and that didn't seem to help.

May I have some more clarification?

THANKS,

Jerry
Gridview is an ASP.Net control under the System.Web.UI.WebControls class as is the repeater, the DataGridView is the WindowsForm version.

I have one inherited Windows Form app and I haven't done much with it. I have a project to convert it to a web version in 2013.

Here is the MSDN page on the DataGridView:
http://msdn.microsoft.com/en-us/library/e0ywh3cz%28v=vs.100%29.aspx
Avatar of JDL129

ASKER

jmiller1979!!!  

Thanks for the post but I'm still in the dark.  It looks like there is some neat stuff you have posted but I don't have a clue as to what to do with it.  I have a table that has about 15 fields in it and I would like to put it on a form where I could have all of the fields displayed on the form at the same time as one row of data.  There may be multiple rows for each patient.

I'm not sure this is clear, so if not just post back!!!

THANKS,

Jerry
ASKER CERTIFIED SOLUTION
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDL129

ASKER

Thanks jmiller!!!!