DataGrid Read Footer TextBox

  • Thread starter Thread starter williamfrenette
  • Start date Start date
W

williamfrenette

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.
 
Make sure you're only looking with FindControl() in the Footer, not in the
header or items.
 
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
 
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top