Button outside datagrid

S

sri_san

Hello group,
I have a datagrid(dg) and a couple of buttons outside the
dg( 'New'& 'Done'). Have a 'save' button inside the dg that responds
to itemcommand event. On a 'New' button click, the footer(textbox) is
displayed in the dg which acts like a new row addition. the 'save'
button corresponds to the footer textbox and hence triggers the
itemcommand event on a save and the logic to add it as a row to the dg
goes in there.
Now, I need to trigger the same event when one clicks the
'Done' button which is outside the datagrid. Can I get a handle of the
footer(textbox) in the 'Done' event click.
Any help would be appreciated!!

Thanks,
Sam.
 
J

John Saunders

Hello group,
I have a datagrid(dg) and a couple of buttons outside the
dg( 'New'& 'Done'). Have a 'save' button inside the dg that responds
to itemcommand event. On a 'New' button click, the footer(textbox) is
displayed in the dg which acts like a new row addition. the 'save'
button corresponds to the footer textbox and hence triggers the
itemcommand event on a save and the logic to add it as a row to the dg
goes in there.
Now, I need to trigger the same event when one clicks the
'Done' button which is outside the datagrid. Can I get a handle of the
footer(textbox) in the 'Done' event click.

You don't need to trigger the same event in order to get the same code
executed. Have the save event execute a subroutine and have the same
subroutine executed by the Done button click event:

private void dg_ItemCommand(object sender, DataGridItemEventArgs e)
{
if (e.CommandName == "Save")
{
SaveData();
}
}

private void Done_Click(object sender, EventArgs e)
{
SaveData();
}

private void SaveData()
{
// Save the data from the footer controls
}

John Saunders
 
S

sri_san

Since, its a footer item I am trying to access. The code below seems
to work great!

DataGridItem
dgi=this.DataGrid1.Controls[0].Controls[this.DataGrid1.Controls[0].Controls.
Count-1] as DataGridItem;
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top