DataGrid Read Footer TextBox

Discussion in 'ASP .Net' started by williamfrenette@gmail.com, Mar 3, 2006.

  1. Guest

    To add record into my grid I use the footer way like explain here :
    http://aspnet.4guysfromrolla.com/articles/021203-1.aspx

    But i dont want a Add button on each row so i call the showfooter with
    another button.

    DBEditDataGrid.ShowFooter := true;
    DBEditDataGrid.SelectedIndex := DBEditDataGrid.Items.Count;
    LoadDataFromDB;
    DataBindGrid;

    The problem is that i dont have the ( e As DataGridCommandEventArgs )
    to go read in textbox with something like :

    var txtStorID :TextBox;
    txtStorID = e.Item.FindControl('add_storID')

    So i tried: DataGrid.FindControl('add_storID');

    but the object dont exist...

    By the way im with Delphi but if you have a vb or c# idea it would be
    great too.

    Thank you.
     
    , Mar 3, 2006
    #1
    1. Advertising

  2. Make sure you're only looking with FindControl() in the Footer, not in the
    header or items.

    <> wrote in message
    news:...
    > To add record into my grid I use the footer way like explain here :
    > http://aspnet.4guysfromrolla.com/articles/021203-1.aspx
    >
    > But i dont want a Add button on each row so i call the showfooter with
    > another button.
    >
    > DBEditDataGrid.ShowFooter := true;
    > DBEditDataGrid.SelectedIndex := DBEditDataGrid.Items.Count;
    > LoadDataFromDB;
    > DataBindGrid;
    >
    > The problem is that i dont have the ( e As DataGridCommandEventArgs )
    > to go read in textbox with something like :
    >
    > var txtStorID :TextBox;
    > txtStorID = e.Item.FindControl('add_storID')
    >
    > So i tried: DataGrid.FindControl('add_storID');
    >
    > but the object dont exist...
    >
    > By the way im with Delphi but if you have a vb or c# idea it would be
    > great too.
    >
    > Thank you.
    >
     
    Ken Cox - Microsoft MVP, Mar 4, 2006
    #2
    1. Advertising

  3. Hi William,

    Because when creating datagrid, the control's ID in datagrid is recreated.
    You need use new ID to get its reference:

    In footer, it seems like

    newId = datagrid.ID + ":_ctl" + (datagrid.Items.Count + 2) + ":" + Original_ID

    Then you can use (C#)

    this.FindControl(newId)

    Or more precisely, you can get its id by its ClientID in
    datagrid_ItemDataBound event:

    if (e.Item.ItemType == ListItemType.Footer)
    {
    TextBox txt = e.Item.FindControl("txtIn") as TextBox;
    string txtId = txt.ClientID.Replace("__", ":_").Replace("_" + txt.ID,
    ":" + txt.ID) ;
    }

    To store it in ViewState or Session, then when postback you use it.

    HTH

    Or more
    Elton Wang



    HTH


    "" wrote:

    > To add record into my grid I use the footer way like explain here :
    > http://aspnet.4guysfromrolla.com/articles/021203-1.aspx
    >
    > But i dont want a Add button on each row so i call the showfooter with
    > another button.
    >
    > DBEditDataGrid.ShowFooter := true;
    > DBEditDataGrid.SelectedIndex := DBEditDataGrid.Items.Count;
    > LoadDataFromDB;
    > DataBindGrid;
    >
    > The problem is that i dont have the ( e As DataGridCommandEventArgs )
    > to go read in textbox with something like :
    >
    > var txtStorID :TextBox;
    > txtStorID = e.Item.FindControl('add_storID')
    >
    > So i tried: DataGrid.FindControl('add_storID');
    >
    > but the object dont exist...
    >
    > By the way im with Delphi but if you have a vb or c# idea it would be
    > great too.
    >
    > Thank you.
    >
    >
     
    =?Utf-8?B?RWx0b24gVw==?=, Mar 4, 2006
    #3
  4. Guest

    Thank you

    The real problem with Delphi is this line:

    var txtPrjCod : TextBox;

    txtPrjCod := DataGrid.FindControl('DBEditDataGrid__ctl4_addPrjCod');

    It dont want to convert the control to textbox type.
    It give an incompatible type: textbox, control error.
    I tried many things to convert it but im out of idea.

    With C# I would only do
    txtPrjCod :=
    (textbox)DBEditDataGrid.FindControl('DBEditDataGrid__ctl4_addPrjCod');

    But delphi kind of suck with these cast function.

    DBEditDataGrid__ctl4_addPrjCod is good (i looked in the source code of
    the html page)

    Thank u
     
    , Mar 6, 2006
    #4
    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. Roger Moore
    Replies:
    0
    Views:
    750
    Roger Moore
    Jul 7, 2003
  2. Darren Spooner

    remove a control from a datagrid footer

    Darren Spooner, Oct 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    350
    Alvin Bruney
    Oct 15, 2003
  3. Replies:
    0
    Views:
    2,397
  4. DAC
    Replies:
    0
    Views:
    143
  5. Henrik
    Replies:
    1
    Views:
    428
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page