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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:20:21+00:00 2026-06-08T23:20:21+00:00

I have a database that holds users documents. The Users can store their own

  • 0

I have a database that holds users documents. The Users can store their own meta-data to each document and to accomedate this I have 20 “Key” fields. Each user can use 1 to 20 columns and rename them and order them in the gridview as they please.

The document table looks like this

Documents:
ID int primary key identity,
SiteID int foreign key references sites(id),
PDFFolder varchar(100),
Key1 varchar(300),
keyN varchar(300);  //Upto 20 keys

Now I have another table called KeyNames:

KeyNames:
ID int primary key identity,
SiteId int foriegn key references sites(id),
KeyName1 varchar(50),
KeyOrder1 int,         //1 is Textbox, 2 is Multi Choice, 3 is date ect
KeyType1 int,
KeyNameN varchar(50),   //Repeat 20times
KeyOrderN int,
KeyTypeN int

The Current method I am using is to get a DataTable of the documents for a certain user (who owns a site)

DataTable documents = GetDocuments(int userId, int siteId);

Then I change the Order and the Heading of each Key, If the order < 0 then its removed

   //Set Order of Keys
    if ((keys.KeyOrder1 <0) || (keys.KeyOrder1 == null))
    { 
        documentsTable.Columns.Remove("Key1");
   }
   else
    {
        documentsTable.Columns["Key1"].SetOrdinal((int)keys.KeyOrder1);
        documentsTable.Columns["Key1"].ColumnName = keys.Keyname1;                
    }

    //Repeat 20 times

now I simply set the datasource of my gridview to the DataTable and Bind

this.Session["documents"] = documentsTable; //Save to session for future use
gvMail.DataSource = documentsTable;
gvMail.DataBind();

All works well except now I need to make it so the user can edit each Key and save it back to the database. To make things harder, when each row is put in editview I want it to be either a Textbox or DropDownView (in future ill use JavaScript to make a date picker, but not for this example).

I have tried to reverse the process

 protected void btnEdit_Click(Object sender, EventArgs e)
 {
        Button btn = sender as Button;
        GridViewRow row = (GridViewRow)btn.NamingContainer;

        if (btn.Text == "Edit")
        {
            for (int i = 0; i < row.Cells.Count; i++)
            {
               //Get Header
               string header = gvMail.HeaderRow.Cells[i].Text;
               //Get Keys
               KeyName keys = db.GetKeys(SiteID);
               //Cycle through keys to find right key 
               //ie if (keys.KeyName1 == header)
               //  {
               //    switch (keys.KeyType1)
                     {
                        case 1: //Add Textbox
                        case 2: //add drop down box code
               //  }
        }

A couple of the many problem I have is it requires i repeat code 20 times to cycle through all the keys to find which key it is and find the type.

Then the next problem is when I add a control by:

                    TextBox txtBox = new TextBox();
                    txtBox.Text = row.Cells[i].Text;

                    row.Cells[i].Controls.Add(txtBox);

it does not exist after the postback..

  • 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-06-08T23:20:23+00:00Added an answer on June 8, 2026 at 11:20 pm

    Why don’t you use Template Columns in DataGridView to create TextBox and DropDown list columns? It’s very simple and easy and will solve your issue to clearing controls after postback.

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

Sidebar

Related Questions

I have a database table which holds meta data about images, the field in
I have been working on a database that holds order numbers and order information.
I have a Database that contains data about articles , structures and manufacturers .
I have a SQL Server that holds a lot of data. An application, running
I have a database that holds the name of Python functions and a string
I have a table in my database that holds numerical values collected from a
I have a string that holds user input. This string can contain various types
I keep having complaints that users are logged in as each other. They can
We have a simple database. The User table holds users. The Accounts table holds
I have a database table which holds each user's checkins in cities. I need

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.