Adding an HtmlInputControl and writing the data

Discussion in 'ASP .Net Datagrid Control' started by DomNewbie, Jun 6, 2006.

  1. DomNewbie

    DomNewbie Guest

    I have added a template column with a file field in the
    EditItemTemplate. The ItemTemplate contains a databound label. I'm
    wondering how best to not lose the data when invoking the edit command
    and how best to write data back to the database when a new file is
    selected.

    Below is as far as I've got!!

    private void DataGrid1_UpdateCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {

    string[] values=new string[16] ;
    bool isFile=false;
    DataTable dt=td.Projects;

    // Gets the value of the key field of the row being updated
    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();



    // Gets the value the TextBox control
    for(int i = 1; i < e.Item.Cells.Count-1; i++)
    {
    if
    (e.Item.Cells.Controls[0].GetType().ToString()=="System.Web.UI.LiteralControl")
    {
    isFile=true;
    LiteralControl lc =
    (LiteralControl)(e.Item.Cells.Controls[0]);
    string filenam=lc.Text;


    }
    if
    (e.Item.Cells.Controls[0].GetType().ToString()=="System.Web.UI.WebControls.TextBox")
    {
    TextBox tb = (TextBox)(e.Item.Cells.Controls[0]);
    values= tb.Text;
    if (isFile)
    {
    values[i-1]= tb.Text;
    isFile=false;
    }
    }

    }

    int j=0;

    foreach (DataRow r in dt.Rows)
    {
    if (r.ItemArray[0].ToString() ==key)
    {

    for(int i = 1; i < e.Item.Cells.Count-1; i++)
    {
    try
    {
    r = values;
    }
    catch
    {
    lblError.Text = lblError.Text + "\r\n" + "Invalid
    value in the field " + dt.Columns.ColumnName + "**";
    }
    }
    }
    j +=1;

    }


    td.updateProjects(dt);
    DataGrid1.EditItemIndex = -1;
    this.DataGrid1.DataSource=dt;

    DataGrid1.DataBind();

    }
    DomNewbie, Jun 6, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Scheel
    Replies:
    3
    Views:
    767
    Jacob Yang [MSFT]
    Nov 26, 2003
  2. HNguyen
    Replies:
    4
    Views:
    2,399
    HNguyen
    Dec 21, 2004
  3. Paul Smith

    Adding Data To Data Base

    Paul Smith, Aug 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    375
    John Rivers
    Aug 30, 2005
  4. Neo Geshel
    Replies:
    2
    Views:
    727
    Neo Geshel
    Nov 17, 2005
  5. Replies:
    0
    Views:
    3,858
Loading...

Share This Page