Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i am using Datagrid in my silverlight 4 application

In the DataGrid I have a template column with a TextBox.
Runtime i have added this to the grid row.

Now I want to read that newly added textbox and save it to the database on save button click.
This save button is outside the grid.

My class is as
 public class Employee
{
   public int EmpID{get;set;}
    public string EmpName{get;set;}
    public string EmpAddress{get;set;}
    
}

I am using a datagrid with a templatecolumn like below with ItemSource set as List<employee>
<data:datagridtemplatecolumn width="100" xmlns:data="#unknown">
  <data:datagridtemplatecolumn.celltemplate>
    <datatemplate>
<textbox name="txt_EmpName" acceptsreturn="True" text="{Binding EmpName}"></textbox>
    </datatemplate>
   </data:datagridtemplatecolumn.celltemplate>
  </data:datagridtemplatecolumn>

and the button click event handler is
private void btn_save_Click(object sender, System.Windows.RoutedEventArgs e)
{}


Please please please guide me..

Ho i access this textbox and achieve my target.

Thanks in advance
Posted
Comments
Herman<T>.Instance 11-Aug-11 13:37pm    
in c# it is:
basically you have to cast the sender to the desired object.
Example:
Button btnPressed = (Button)sender;
DataGridRow theRow = (DataGridRow)btnPressed.NamingContainer;

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900