troubleshooting Question

Acessing a datagrid from a control using findcontrol.

Avatar of Sanjeet
SanjeetFlag for United States of America asked on
.NET Programming
1 Comment1 Solution523 ViewsLast Modified:
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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros