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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:21:55+00:00 2026-05-12T05:21:55+00:00

I do have a page that has a TextBox a Button and a Datagrid.

  • 0

I do have a page that has a TextBox a Button and a Datagrid.

The goal here is simple : Each time I input something in the TextBox and press the Button, it does a little check and then it adds the item to the datagrid and a business logic datasource.

The problem is, if I want to make the item appear in the DataGrid I have to do a datagrid.DataSource = myBusinessObject; datagrid.DataBind(); problem with that is I lose the viewstate and the choice in the radiobox the user have done.

Here is the Template :

            <asp:TextBox ID="txtDomain" runat="server" style="margin-bottom: 0px" 
                Width="254px"></asp:TextBox>
                &nbsp;<asp:Button ID="domainAdd" runat="server" onclick="domainAdd_Click" 
                style="height: 26px" Text="Ajouter" />
            &nbsp;<br />
            <br />
            <asp:DataGrid ID="dg1" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundColumn DataField="Name" HeaderText="Nom choisi"></asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="Enregistrer">
                        <ItemTemplate>
                            <asp:RadioButton ID="register" runat="server" GroupName="domaine_action" Checked='<%# Bind("IsRegister")%>' Enabled='<%# Bind("CanRegister")%>' />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Transférer">
                        <ItemTemplate>
                            <asp:RadioButton ID="transfert" runat="server" GroupName="domaine_action" Checked='<%# Bind("IsTransfert")%>' Enabled='<%# Bind("CanTransfert")%>' />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Gérer moi même">
                        <ItemTemplate>
                            <asp:RadioButton ID="manage" runat="server" GroupName="domaine_action" Checked='<%# Bind("IsSelfManaged")%>' Enabled='<%# Bind("CanSelfManage")%>' />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>

The code behind :

    protected void domainAdd_Click(object sender, EventArgs e)
    {
        if (Session["dic"] != null)
        {
            var _dic = (List<Test1>)Session["dic"];

            _dic.Add(new Test1 { Name = txtDomain.Text });

            dg1.DataSource = _dic;
            dg1.DataBind();

            Session["dic"] = _dic;
        }
        else
        {
            List<Test1> _dic = new List<Test1>();

            _dic.Add(new Test1 { Name = txtDomain.Text });

            dg1.DataSource = _dic;
            dg1.DataBind();

            Session["dic"] = _dic;
        }

For now the Test1 object is just a little class to map fields for business logic.

public class Test1
{
    public string Name { get; set; }

    public string IsRegister { get; set; }
    public string IsTransfert { get; set; }
    public string IsSelfManaged { get; set; }

    public string CanRegister { get; set; }
    public string CanTransfert { get; set; }
    public string CanSelfManage { get; set; }
}

So I guess the direct question would be : How to add items to the grid & the business object without loosing the choices of radioboxes in the grid.

  • 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-12T05:21:55+00:00Added an answer on May 12, 2026 at 5:21 am

    You’re going to have to save the state of the radioboxes in your business object before adding a new item the List, so that when you bind it again, the choices will be reflected back in the datagrid.
    If you’re doing that, you might as well disable the ViewState for the grid…

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

Sidebar

Related Questions

I have a PHP page that has 1 textbox and when I press on
I have an ASP.NET page that has two input elements: A TextBox that is
I have a page that has a button, that when clicked opens up a
I have a page that contains an element (a TextBox) that has two CSS
I have a page with multiple textboxes and each has a button associated with
I have a page that has an iframe From one of the pages within
I have a Page that has a single instance of a UserControl that itself
In a web application, I have a page that contains a DIV that has
We have a page that ordinarily has two elements arranged side-by-side. Despite exploring a
I have a login page that has several textboxes on the page, one of

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.