locked
Confused over which control can be used - similar to a table RRS feed

  • Question

  • User2015884762 posted

    Hi, I am kind of new to the asp.net, would like some suggestion on how I can use the controls to achieve what I need

    I would need something similar to the table below : -

    Basically, the user would need to enter the values the specific computer name in the corresponding columns of which their headers are dates.

    What type of controls can I use to achieve the above, I have seen repeater and grid control, but it does not seem to suit what I need.

    ComputerName

    Date1

    Date2

    Date3

    Date4

    Date4

    Date5

    Date6

    Date7

    PC1

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    PC2

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    PC3

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    PC4

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    PC5

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    PC6

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Textbox

    Wednesday, January 16, 2019 8:00 AM

Answers

  • User-2054057000 posted

    GridView can do any work like you want. You should use GridView control.

    These will be the columns of the GridView and you will add templatefield to add textboxes that will be binded with values from #Eval().

    These columns are:

    ComputerName

    Date1

    Date2

    Date3

    Date4

    Date4

    Date5

    Date6

    Date7

    Kindly see this tutorial on GridView - https://www.c-sharpcorner.com/UploadFile/009464/bind-gridview-using-dataset-in-Asp-Net/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 16, 2019 10:12 AM
  • User-1174608757 posted

    Hi  callykalpana,

    According to your description, I suggest you to use GridView control. GridView will show data as a table format.

    You  could put textbox control  in the template of Gridview.Here is a demo ,I hope it could help you.

    Gridview.aspx:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> 
                    <Columns>
                        <asp:TemplateField HeaderText="ComputerName">
                            <ItemTemplate>
                                <%#Eval("ComputerName") %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date1">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date2">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date3">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </form>
    </body>

    GridView.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication1._1._17
    {
        public partial class Gridview : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add(new DataColumn("ComputerName", typeof(string)));
                    DataRow row1 = dt.NewRow();
                    row1["ComputerName"] = "PC1";
                    DataRow row2 = dt.NewRow();
                    row2["ComputerName"] = "PC2";
                    DataRow row3 = dt.NewRow();
                    row3["ComputerName"] = "PC3";
                    dt.Rows.Add(row1);
                    dt.Rows.Add(row2);
                    dt.Rows.Add(row3);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
    
            }
        }
    }

    It shows what you want as below:

    Best Regards 

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 17, 2019 4:40 AM

All replies

  • User-2054057000 posted

    GridView can do any work like you want. You should use GridView control.

    These will be the columns of the GridView and you will add templatefield to add textboxes that will be binded with values from #Eval().

    These columns are:

    ComputerName

    Date1

    Date2

    Date3

    Date4

    Date4

    Date5

    Date6

    Date7

    Kindly see this tutorial on GridView - https://www.c-sharpcorner.com/UploadFile/009464/bind-gridview-using-dataset-in-Asp-Net/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 16, 2019 10:12 AM
  • User-1174608757 posted

    Hi  callykalpana,

    According to your description, I suggest you to use GridView control. GridView will show data as a table format.

    You  could put textbox control  in the template of Gridview.Here is a demo ,I hope it could help you.

    Gridview.aspx:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> 
                    <Columns>
                        <asp:TemplateField HeaderText="ComputerName">
                            <ItemTemplate>
                                <%#Eval("ComputerName") %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date1">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date2">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Date3">
                            <ItemTemplate>
                                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </form>
    </body>

    GridView.aspx.cs:

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication1._1._17
    {
        public partial class Gridview : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add(new DataColumn("ComputerName", typeof(string)));
                    DataRow row1 = dt.NewRow();
                    row1["ComputerName"] = "PC1";
                    DataRow row2 = dt.NewRow();
                    row2["ComputerName"] = "PC2";
                    DataRow row3 = dt.NewRow();
                    row3["ComputerName"] = "PC3";
                    dt.Rows.Add(row1);
                    dt.Rows.Add(row2);
                    dt.Rows.Add(row3);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
    
            }
        }
    }

    It shows what you want as below:

    Best Regards 

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 17, 2019 4:40 AM