Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Grid View

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
0
0
US
I have a page that has drop down list and a user control

The user control generate graphs and data grids for web enabled reports.
Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            uc_report.sChartType = ddlChartType.SelectedValue;
        }

Inside my UC i have
Code:
<asp:UpdatePanel ID="FusionChartsUP" runat="server">
    <ContentTemplate>
        <asp:Panel ID="pnlChart" runat="server" Width="950px" Height="100%" ></asp:Panel>

        <asp:Panel ID="pnlData" runat="server" Width="950px" Height="100%" >  </asp:Panel>
        <asp:GridView ID="gvData" runat="server" ForeColor="#333333">
            <AlternatingRowStyle BackColor="White" ForeColor="#333333" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        </asp:GridView>

    </ContentTemplate>
</asp:UpdatePanel>

I have 17 different reports. However, here is what is happening. As I change the drop down list for each chart type, the graph is generated and the grid is created. I am adding the grids to the pnlData but when I try to loop through the cells and format them, it only seems to work the first time.

Any ideas or suggestions? I have tried a bunch of different things, and not sure what I am doing wrong here. I am guessing this is because of the update panel or I have something setup wrong with the update panel.



Code:
switch (iEncounterType.ToString())
                    {
                        case "1":
                            //Admissions By Financial Class  

                                gvData_Counts_Admits.ShowHeader = true;
                                gvData_Counts_Admits.ID = "gvData_Counts_Admits";
                                gvData_Counts_Admits.Width = Unit.Pixel(950);
                                gvData_Counts_Admits.AlternatingRowStyle.BackColor = Color.White;
                                gvData_Counts_Admits.AlternatingRowStyle.ForeColor = Color.Black;
                                gvData_Counts_Admits.RowStyle.BackColor = Color.FromArgb(247, 246, 243);
                                gvData_Counts_Admits.RowStyle.ForeColor = Color.Black;
                                gvData_Counts_Admits.DataSource = null;
                                gvData_Counts_Admits.DataBind();
                                gvData_Counts_Admits.DataSource = dtDisplay;
                                gvData_Counts_Admits.DataBind();

                                
                                gvData_Counts_Admits_Pct.ShowHeader = true;
                                gvData_Counts_Admits_Pct.ID = "gvData_Counts_Admits_Pct";
                                gvData_Counts_Admits_Pct.Width = Unit.Pixel(950);
                                gvData_Counts_Admits_Pct.AlternatingRowStyle.BackColor = Color.White;
                                gvData_Counts_Admits_Pct.AlternatingRowStyle.ForeColor = Color.Black;
                                gvData_Counts_Admits_Pct.RowStyle.BackColor = Color.FromArgb(247, 246, 243);
                                gvData_Counts_Admits_Pct.RowStyle.ForeColor = Color.Black;
                                gvData_Counts_Admits_Pct.DataSource = null;
                                gvData_Counts_Admits_Pct.DataBind();
                                gvData_Counts_Admits_Pct.DataSource = dtDisplay_Pct;
                                gvData_Counts_Admits_Pct.DataBind();

                                pnlData.Controls.Add(gvData_Counts_Admits);
                                pnlData.Controls.Add(new LiteralControl("<br/><br/>"));
                                pnlData.Controls.Add(gvData_Counts_Admits_Pct);
                                

                                //========================================================================
                                rowscount = gvData_Counts_Admits.Rows.Count;

                                for (int x = 0; x < rowscount; x++)
                                {
                                    for (int i = 0; i < gvData_Counts_Admits.Rows[0].Cells.Count; i++)
                                    {
                                        if (i > 0)
                                        {
                                            gvData_Counts_Admits.Rows[x].Cells[i].Width = Unit.Pixel(125);

                                            int iResult;

                                            if (gvData_Counts_Admits.Rows[x].Cells[i].Text != "&nbsp;")
                                            {

                                                //iResult = Convert.ToInt32(gvData_Counts_Admits.Rows[x].Cells[i].Text);
                                                //gvData_Counts_Admits.Rows[x].Cells[i].Text = String.Format("{0:#,###0}", iResult);
                                            }

                                        }

                                        gvData_Counts_Admits.Rows[x].Cells[i].HorizontalAlign = HorizontalAlign.Center;

                                    }
                                }
                                //========================================================================

                                //========================================================================
                                rowscount_pct = gvData_Counts_Admits_Pct.Rows.Count;

                                for (int x = 0; x < rowscount_pct; x++)
                                {
                                    for (int i = 0; i < gvData_Counts_Admits_Pct.Rows[0].Cells.Count; i++)
                                    {
                                        if (i > 0)
                                        {
                                            gvData_Counts_Admits_Pct.Rows[x].Cells[i].Width = Unit.Pixel(125);

                                            decimal dResult;

                                            if (gvData_Counts_Admits_Pct.Rows[x].Cells[i].Text != "&nbsp;")
                                            {

                                                //dResult = Convert.ToDecimal(gvData_Counts_Admits_Pct.Rows[x].Cells[i].Text);
                                                //gvData_Counts_Admits_Pct.Rows[x].Cells[i].Text = String.Format("{0:p0}", dResult);
                                            }

                                        }

                                        gvData_Counts_Admits_Pct.Rows[x].Cells[i].HorizontalAlign = HorizontalAlign.Center;

                                    }
                                }
                                //========================================================================


                            break;
                        case "2":
                            //Observations By Financial Class
                                
                                gvData_Counts_Observations.ShowHeader = true;
                                gvData_Counts_Observations.ID = "gvData_Counts_Observations";
                                gvData_Counts_Observations.Width = Unit.Pixel(950);
                                gvData_Counts_Observations.AlternatingRowStyle.BackColor = Color.White;
                                gvData_Counts_Observations.AlternatingRowStyle.ForeColor = Color.Black;
                                gvData_Counts_Observations.RowStyle.BackColor = Color.FromArgb(247, 246, 243);
                                gvData_Counts_Observations.RowStyle.ForeColor = Color.Black;
                                gvData_Counts_Observations.DataSource = null;
                                gvData_Counts_Observations.DataBind();
                                gvData_Counts_Observations.DataSource = dtDisplay;
                                gvData_Counts_Observations.DataBind();

                                
                                gvData_Counts_Observations_Pct.ShowHeader = true;
                                gvData_Counts_Observations_Pct.ID = "gvData_Counts_Observations_Pct";
                                gvData_Counts_Observations_Pct.Width = Unit.Pixel(950);
                                gvData_Counts_Observations_Pct.AlternatingRowStyle.BackColor = Color.White;
                                gvData_Counts_Observations_Pct.AlternatingRowStyle.ForeColor = Color.Black;
                                gvData_Counts_Observations_Pct.RowStyle.BackColor = Color.FromArgb(247, 246, 243);
                                gvData_Counts_Observations_Pct.RowStyle.ForeColor = Color.Black;
                                gvData_Counts_Observations_Pct.DataSource = null;
                                gvData_Counts_Observations_Pct.DataBind();
                                gvData_Counts_Observations_Pct.DataSource = dtDisplay_Pct;
                                gvData_Counts_Observations_Pct.DataBind();

                                pnlData.Controls.Add(gvData_Counts_Observations);
                                pnlData.Controls.Add(new LiteralControl("<br/><br/>"));
                                pnlData.Controls.Add(gvData_Counts_Observations_Pct);


                                //========================================================================
                                rowscount = gvData_Counts_Observations.Rows.Count;

                                for (int x = 0; x < rowscount; x++)
                                {
                                    for (int i = 0; i < gvData_Counts_Observations.Rows[0].Cells.Count; i++)
                                    {
                                        if (i > 0)
                                        {
                                            gvData_Counts_Observations.Rows[x].Cells[i].Width = Unit.Pixel(125);

                                            int iResult;

                                            if (gvData_Counts_Observations.Rows[x].Cells[i].Text != "&nbsp;")
                                            {

                                                //iResult = Convert.ToInt32(gvData_Counts_Observations.Rows[x].Cells[i].Text);
                                                //gvData_Counts_Observations.Rows[x].Cells[i].Text = String.Format("{0:#,###0}", iResult);
                                            }

                                        }

                                        gvData_Counts_Observations.Rows[x].Cells[i].HorizontalAlign = HorizontalAlign.Center;

                                    }
                                }
                                //========================================================================

                                //========================================================================
                                rowscount_pct = gvData_Counts_Observations_Pct.Rows.Count;

                                for (int x = 0; x < rowscount_pct; x++)
                                {
                                    for (int i = 0; i < gvData_Counts_Observations_Pct.Rows[0].Cells.Count; i++)
                                    {
                                        if (i > 0)
                                        {
                                            gvData_Counts_Observations_Pct.Rows[x].Cells[i].Width = Unit.Pixel(125);

                                            decimal dResult;

                                            if (gvData_Counts_Observations_Pct.Rows[x].Cells[i].Text != "&nbsp;")
                                            {

                                                //dResult = Convert.ToDecimal(gvData_Counts_Observations_Pct.Rows[x].Cells[i].Text);
                                                //gvData_Counts_Observations_Pct.Rows[x].Cells[i].Text = String.Format("{0:p0}", dResult);
                                            }

                                        }

                                        gvData_Counts_Observations_Pct.Rows[x].Cells[i].HorizontalAlign = HorizontalAlign.Center;

                                    }
                                }
                                //========================================================================


                            
                            break;
 
What do you mean it only seems to work the first time? Do you get an error(s)?
 
No errors but If i choose a different version of the report and it runs through the code again. The datatable has the correct values, but the gridview does not get them. If I leave these commented out, the values switch.

Code:
//dResult = Convert.ToDecimal(gvData_Counts_Observations_Pct.Rows[x].Cells[i].Text);
//gvData_Counts_Observations_Pct.Rows[x].Cells[i].Text = String.Format("{0:p0}", dResult);
 
What happens when you trace through the code you commented out, what values do you see?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top