Solved

How can you work with programmatic Datatables in Gridviews to allow for editing and deleting of columns and rows.

Posted on 2007-04-04
3
299 Views
Last Modified: 2010-04-15
I have a situation where I have programmatically created a temporary Datatable that is persistent in memory while the data is manipulated...rows are added...and values of columns can be edited..as well as rows being deleted from this table via the gridview.

Once the user is finished manipulating the data they click a button and everything writes to the database into the appropriate tables.

Well at least that is the functionality I need..

I have the Datatable and am currently using the Session to store the object temporarily while the user manipulates the data...

I can even bind the table to the gridview so that the data is displayed.

WHat I cant figure out is how to configure the gridview to allow me to edit the data in the rows and delete rows...normally if the table was created with a dataset I could just set an object datasource to the TableAdapter business object in the dataset and then if I bind the gridview to the ObjectDatasource I get all kinds of optionds to allow me to edit delte etc etc. and its easy to convert the fields to templates...

But how can you do this when your datatable is temporary and built programmatically?
I dont really want to have to be reading and writing and deleting from the database for this but I suppose if I hae to I have to...
0
Comment
Question by:Prysson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 18853707
In such a situation we always used a grid like this one
http://www.infragistics.com/dotnet/netadvantage/winforms/wingrid.aspx#Overview
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18853771
In addition I can't figure out your troubles.  I created tables/dataset in memory without any problem.
http://msdn2.microsoft.com/en-us/library/ss7fbaez.aspx
0
 

Author Comment

by:Prysson
ID: 18860124
I have foudn a better way to explain this..hopefully you can help me out.

This is my code that create my table programmatically and loads it into memory...

public DataTable MakeTable()
    {
        DataTable dto = new DataTable();
        DataColumn col;

        col = new DataColumn();
        col.DataType = System.Type.GetType("System.Int32");
        col.ColumnName = "ID";
        dto.Columns.Add(col);
       
        col = new DataColumn();
        col.DataType = System.Type.GetType("System.String");
        col.ColumnName = "Products";
        dto.Columns.Add(col);

        col = new DataColumn();
        col.DataType = System.Type.GetType("System.Int32");
        col.ColumnName = "Quantity";
        dto.Columns.Add(col);

        col = new DataColumn();
        col.DataType = System.Type.GetType("System.Int32");
        col.ColumnName = "Price";
        dto.Columns.Add(col);

        return dto;
    }

    private void AddData(string prod, int quantity, int prodid, int price, DataTable dto)
    {
        DataRow row;
        row = dto.NewRow();
        row["Products"] = prod;
        row["Quantity"] = quantity;
        row["ID"] = prodid;
        row["Price"] = price;
        dto.Rows.Add(row);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {

            DataTable dto = new DataTable();
            dto = MakeTable();
            Session["prodDT"] = dto;

           
       

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string prod = "Frontenac";
        int quantity = 101;
        int prodid = 1;
        int price = 12;
        AddData(prod, quantity, prodid, price, (DataTable)Session["prodDT"]);


    }



Now let's say I have a GridView1 and I  want to create a template field that is a textbox and I want to bind the TEXT property of that to the "Quantity" COlumn of this datatable...HOw would I do that. I am guessing the answer lies in the asp code somewhere...

<asp:GridView ID="GridView1" runat="server">
            <Columns>
                <asp:TemplateField HeaderText="Quantity">
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text="????"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>  

BUt I am not certain what the code needs to be to bind that item template to the table column...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question