Link to home
Start Free TrialLog in
Avatar of Sanjeet
SanjeetFlag for United States of America

asked on

Acessing a datagrid from a control using findcontrol.

I have an ascx page called main.ascx.

Main.ascx contains 2 controls. dailyevents1 and concuentevents1

Each of these controls contains a datagrid.

the main.ascx page also contains a submit link.

the submit link should sum up the contents of the 5th column in eash datagrid and display the total at the bottom of each datagrid.


I have this so far I just need to reference the datagrids using the find control method:

            private void lbsubmit_Click(object sender, System.EventArgs e)
            {
                  dailyEvent = FindControl( "DailyEvent1") as DailyEvent;

                  DataGrid dg = FindControl( "DailyEvent1" ) as DataGrid;

                  

                        TextBox tb = (TextBox)e.Item.Cells[5].FindControl("txtCreditsClaimed");
            
                  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                  {
                  
                        //if(e.Item.Cells[5].Text.ToString() != null  || e.Item.Cells[5].Text.ToString().Length > 0 )
                        if(e.Item.Cells[5].Text.ToString().Length > 0 )
                        {
                              CalcTotal( e.Item.Cells[5].Text);
                              e.Item.Cells[5].Text =string.Format("{0:c}", Convert.ToDouble(e.Item.Cells[5].Text));
                        }
                  }
                  else if(e.Item.ItemType == ListItemType.Footer )
                  {
                        e.Item.Cells[4].Text="Total";
                        e.Item.Cells[5].Text = string.Format("{0:c}", runningTotal);
                  }

            }

Says I cannot use e.items. How do I refereance txtCreditsClaimed inside the datagrid from this submit link.
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial