Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6570367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:44:51+00:00 2026-05-25T14:44:51+00:00

I have simple asp.net page: using System; using System.Configuration; using System.Data; using System.Linq; using

  • 0

I have simple asp.net page:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptTable.DataSource = GetDataFromDB();
            rptTable.DataBind();
        }
    }

    private DataTable GetDataFromDB()
    {
        DataTable table = new DataTable();
        table.Columns.Add("Id", typeof(int));
        table.Columns.Add("Name", typeof(string));

        table.Rows.Add(1, "HDD");
        table.Rows.Add(2, "Video");
        table.Rows.Add(3, "RAM");

        return table;
    }

    protected void rptTable_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        TextBox tbName = (TextBox)e.Item.FindControl("tbName");
        int id = Convert.ToInt32(e.CommandArgument);
        string name = tbName.Text;

        //Category.Save(int id, string name)
        //Rebuild Repeater
    }

}

and aspx code:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
        <asp:Repeater ID="rptTable" runat="server" OnItemCommand="rptTable_ItemCommand">
            <ItemTemplate>
                <tr>
                    <td>
                        <%#Eval("id")%>
                    </td>
                    <td>
                        <asp:TextBox ID="tbName" runat="server" Text='<%#Eval("Name")%>'></asp:TextBox>
                    </td>
                    <td>
                        <asp:Button ID="btnSave" runat="server" Text="Save" CommandArgument='<%#Eval("id")%>' />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
        </table>
    </div>
    </form>
</body>
</html>

It works like simple grid and you are able to edit data directly in the grid.

How can I implement same logic in MVC ?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:44:52+00:00Added an answer on May 25, 2026 at 2:44 pm

    To replicate the asp:Repeater functionality in an MVC application you would normally use a foreach loop with textboxes within bound to model properties.

    You can however if you really want, include an asp:repeater control in an MVC app, but it’s not going to work as you’d expect if it relies on postbacks.

    If it’s a simple read only control, you can put something like the following in your view:

    <scipt runat="server">
        protected void Page_Load(object sender, EventArgs e) {
            rptTable.DataSource = ViewData["yourViewDataList"];
            rptTable.DataBind();
        }
    </script>
    

    This assumes you’ve got something in the ViewData which can be databound, so to do that you’d likley need to create a controller method to build your DataTable as you’ve done in ‘GetDataFromDB()’

    I’m not going to go into the full implementation but at a high level, that’s how you could use the control in MVC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing
i have a problem in asp.net web-application. I'm using UrlRewritingNet.UrlRewrite and it's works fine
I am writing a SharePoint web part which will have a simple ASP.NET form.
I have a Web Application in Asp.Net 4 running locally on IIS 7. I
I am working on simple Workflow Foundation that uses a simple ASP.NET page as
I'm having a simple ASP.NET application hosted on my local IIS6, under Vista. It
I use asp.net 4 and C#. I have some nested Master Pages; I display
I have a page where I am trying to implement a simple two tab
I have a classic ASP website (yes they still exist) that needs to call
In an Asp.net MVC application I'd like to encapsulate the ugly wrapper code (just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.