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

  • Home
  • SEARCH
  • 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 336821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:42+00:00 2026-05-12T10:16:42+00:00

When I am almost done with my application, one final thing is disturbing me.

  • 0

When I am almost done with my application, one final thing is disturbing me.

When I select an Item from DropDown list, GridView1’s columns are showing up two times like this:

alt text

This is my aspx file:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="WebmasterControlPanel.aspx.cs" Inherits="Ice_Web_Portal.UI.Webmaster.WebmasterControlPanel" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table style="width: 288px">
        <tr>
            <td valign="top">
                <asp:DropDownList ID="tableNamesDropDownList1" runat="server" DataSourceID="UserTablesObjectDataSource1"
                    DataTextField="TableName" DataValueField="TableName" Width="256px" OnSelectedIndexChanged="tableNamesDropDownList1_SelectedIndexChanged" AutoPostBack="True">
                </asp:DropDownList><br />
                <asp:ObjectDataSource ID="UserTablesObjectDataSource1" runat="server"
                    SelectMethod="GetAllUserTableNames" TypeName="Ice_Web_Portal.BO.DBTables"></asp:ObjectDataSource>
            </td>
            <td style="width: 3px">
                &nbsp;</td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="GridView1" runat="server" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowCommand="GridView1_RowCommand" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
                </asp:GridView>
            </td>
            <td style="width: 3px">
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td style="width: 3px">
            </td>
            <td>
            </td>
        </tr>
    </table>
</asp:Content>

This is my codebehind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


using System.Web.UI.HtmlControls;

using Ice_Web_Portal.BO;
using Ice_Web_Portal.ASP.NET.Utils;

namespace Ice_Web_Portal.UI.Webmaster
{
    public partial class WebmasterControlPanel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void tableNamesDropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            CreateGridView();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "Edit")
            {
                GridView1.EditIndex = index;

                GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];

                string id = selectedRow.Cells[1].Text;
                string isbn = selectedRow.Cells[2].Text;

                CreateGridView();
            }
            else if (e.CommandName == "Update")
            {                
                LinkButton updateButton = (LinkButton)e.CommandSource;

                DataControlFieldCell dcfc = (DataControlFieldCell)updateButton.Parent;

                GridViewRow gvr = (GridViewRow)dcfc.Parent;

                ControlCollection cc = gvr.Cells[1].Controls;

                TextBox tb = (TextBox)cc[0];

                GridView1.EditIndex = -1;

                CreateGridView();
            }
        }

        private void UpdateTableData()
        {
        }

        private void CreateGridView()
        {
            GridView1.Columns.Clear();

            string tableName = tableNamesDropDownList1.SelectedItem.Text;

            TableNameEnum tableType = TableNameEnumUtility.ConvertToEnum(tableName);

            DataTable dataTable = null;

            if (tableType == TableNameEnum.Book)
            {
                dataTable = Book.GetBooksDataSet().Tables[0];
            }
            else if (tableType == TableNameEnum.Course)
            {
                dataTable = Course.GetCoursesDataSet().Tables[0];
            }
            else
            {
                dataTable = null;
            }

            //Adding Edit Button
            CommandField cf = new CommandField();
            cf.ShowEditButton = true;
            GridView1.Columns.Add(cf);

            if (dataTable != null)
            {
                foreach (DataColumn c in dataTable.Columns)
                {
                    BoundField boundField = new BoundField();

                    boundField.DataField = c.ColumnName;
                    boundField.HeaderText = c.ColumnName;

                    GridView1.Columns.Add(boundField);
                }
            }

            GridView1.DataSource = dataTable;
            GridView1.DataBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
        }
    }
}
  • 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-12T10:16:42+00:00Added an answer on May 12, 2026 at 10:16 am

    Try adding Autogenerate columns set to false

      <asp:GridView ID="GridView1" runat="server" 
    ...
        AutoGenerateColumns="false">
                            </asp:GridView>
    

    defining your gridview

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

Sidebar

Related Questions

Duplicate: Multiple javascript/css files: best practices? Hi guys, my application is almost done but
Almost every Python web framework has a simple server that runs a wsgi application
In almost any Windows application, I notice that holding the mouse button down in
I'm replacing an old web application with a new one, with different structure. I
I'm am currently developing an ASP.NET intranet application. One of the features of this
Almost every Java book I read talks about using the interface as a way
Almost 5 years ago Joel Spolsky wrote this article, The Absolute Minimum Every Software
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
( Almost exact duplicate of Keeping original format POST passing through AWK submitted by
In almost all projects, the choice of the database system is 'almost' automatic ..

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.