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 6805681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:36:59+00:00 2026-05-26T19:36:59+00:00

I have a web user control, that has a table with 3 columns 1)

  • 0

I have a web user control, that has a table with 3 columns
1) GridView in first,
2) filter option (textbox) in second,
3) and another GridView in third.

When I enter text in filter(textbox) some rows gets selected from database and are shown in GridView in third column. This GridView has select button, when it gets pressed, I want that row (or just some columns from it) to be added to GridView in first column.

From what I’ve heard, it is common to use DataTable in theese situations. The code that I have:

public partial class WebUserControl1 : System.Web.UI.UserControl
{
    DataTable tempTable = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        tempTable.Columns.Add("ObjectID");
        tempTable.Columns.Add("Name");
        tempTable.Columns.Add("Price");
        currentDay.DataSource = tempTable;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    }

    protected void objectChooser_SelectedIndexChanged(
        object sender, EventArgs e)
    { 
        DataRow newRow = tempTable.NewRow();
        newRow["ObjectID"] = objectChooser.SelectedRow.Cells[0].Text;
        newRow["Name"] = objectChooser.SelectedRow.Cells[1].Text;
        newRow["Price"] = objectChooser.SelectedRow.Cells[2].Text;           

        tempTable.Rows.Add(newRow);                        
        currentDay.DataBind();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        DataClasses1DataContext dc = new DataClasses1DataContext();

        var objects = from p in dc.VisitingObjects
                  where p.City == tbCityFilter.Text
                  select p;

        objectChooser.DataSource = objects;
        objectChooser.DataBind();
    }
}

But something is wrong with this. When I press select button (in GridView) first time, it works (new value gets added to first GridView, but after that, pressing select button just changes the value in first GridView, but no new rows are added.

Could you please tell me what is wrong with my code, or maybe there is better way to use copy values from GridView1 to GridView2?

  • 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-26T19:37:00+00:00Added an answer on May 26, 2026 at 7:37 pm

    I feel like I’ve said this before…

    You need to store your DataTable somewhere that doesn’t disappear between postbacks. The Session might be a good place to start.

    objects = Session["data"]; //cast this
    if (objects == null)
        //init objects to a new list of your obj type
    objects = objects.Union (
        //your code for filtering grid rows
        );
    Session["data"] = objects;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.Net web user control that contains a TextBox and a calendar
Say that I have a web user control that has several drop down lists
I have a web user control that contains several other (web user) controls and
I have written a user control that captures some user input and has a
I have a data entry web app where the control that has focus is
I have used Subsonic ORM in ASP.NET. It has Scaffold user control that generates
I have created a user control that has an asp:login control in it. I
I have created a user control UserVote that has property to find total vote
I have a web page that uses three controls to allow a user to
I have a web user control with a dropdownlist inside of it. When the

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.