?
Solved

How to get dynamic gridview to populate textboxes at runtime

Posted on 2011-04-22
3
Medium Priority
?
377 Views
Last Modified: 2012-05-11
I am trying to populate a gridview with textboxes dynamically because I don't know how many products a user could have. The columns populate the headertext and the labels, but it doesn't populate the text boxes. I obviously am doing something wrong, but what? I am using a 3 tier architecture and the code is attached. The gridview only loads when a user presses a button and the gridview shows up in a modal window. I am creating the gridview in the availability class.  custom-gridview.txt
0
Comment
Question by:bschave2
  • 3
3 Comments
 

Author Comment

by:bschave2
ID: 35460425
nevermind. I got it. I wasn't adding the template items as columns. Also, I was also using the table column string as the column name which was wrong. I should have put the column name in general.
0
 

Accepted Solution

by:
bschave2 earned 0 total points
ID: 35460738
Here is the code for the solution.
public void getAvailabilityGV(PlaceHolder PH)
        {
            int callOptionCount;
            int DatesCount;

            GridView GV = new GridView();
            GV.Width = Unit.Pixel(700);
            GV.BorderWidth = Unit.Pixel(0);
            GV.AutoGenerateColumns = false;
            GV.ShowFooter = false;
            GV.HeaderStyle.BackColor = ColorTranslator.FromHtml("#6B696B");
            GV.HeaderStyle.ForeColor = ColorTranslator.FromHtml("#FFFFFF");
            GV.HeaderStyle.Font.Bold = true;
            GV.RowStyle.BackColor = ColorTranslator.FromHtml("#F7F7DE");
            GV.AlternatingRowStyle.BackColor = ColorTranslator.FromHtml("#FFFFFF");
            GV.BorderWidth = Unit.Pixel(1);
            GV.BorderColor = ColorTranslator.FromHtml("#6B696B");
            GV.RowStyle.BorderColor = ColorTranslator.FromHtml("#6B696B");
            GV.RowStyle.BorderWidth = Unit.Pixel(1);
            GV.CellPadding = 3;


            ds = dataAccessOPR.getQueryDS
                (
                    Selects.getAvailabilityCount(this.availabilityDate, this.contractId)
                );


            callOptionCount = Convert.ToInt32(ds.Tables[0].Rows[0]["CALL_OPTION_CT"].ToString());
            DatesCount = Convert.ToInt32(ds.Tables[0].Rows[0]["DATES_CT"].ToString());
            string date = ds.Tables[0].Rows[0]["DAYLIGHT_DATE"].ToString();

            ds =
            dataAccessOPR.getQueryDS(Selects.getAvailability(callOptionCount, this.contractId, DatesCount, this.availabilityDate));



            for (int i = 0; i < callOptionCount; i++)
            {
                BoundField hour = new BoundField();
                BoundField id = new BoundField();
                BoundField dateTime = new BoundField();
                BoundField coTypeId = new BoundField();

                TemplateField mwCol = new TemplateField();
                TemplateField resupplyCol = new TemplateField();
                TemplateField adtlMWCol = new TemplateField();
                TemplateField totalMWCol = new TemplateField();
                TemplateField priceCol = new TemplateField();

                int mwTotal;

                if (i == 0)
                {

                    hour.HeaderText = "HOUR";
                    hour.DataField = "HOUR";
                    GV.Columns.Add(hour);

                    id.HeaderText = "Contract ID";
                    id.DataField = "CONTRACT_ID";
                    id.Visible = false;
                    GV.Columns.Add(id);

                    dateTime.HeaderText = "Date Time";
                    dateTime.DataField = "DATE_TIME";
                    dateTime.Visible = false;
                    GV.Columns.Add(dateTime);

                    mwCol.HeaderText = "MW";
                    mwCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "MW");
                    GV.Columns.Add(mwCol);

                    resupplyCol.HeaderText = "Re-supply POR";
                    resupplyCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "resupply_por");
                    GV.Columns.Add(resupplyCol);

                    adtlMWCol.HeaderText = "Adtl MW's POR";
                    adtlMWCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "additional_mw");
                    GV.Columns.Add(adtlMWCol);

                    totalMWCol.HeaderText = "Total MW's POR";
                    totalMWCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "totalMW");
                    GV.Columns.Add(totalMWCol);


                    priceCol.HeaderText = "Price";
                    priceCol.ItemStyle.Width = Unit.Pixel(55);
                    priceCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "price");
                    GV.Columns.Add(priceCol);

                    coTypeId.HeaderText = "Call Option Type ID";
                    coTypeId.DataField = "call_option_type_id";
                    coTypeId.Visible = false;
                }
                else
                {
                    mwCol.HeaderText = "MW";
                    mwCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "MW");
                    GV.Columns.Add(mwCol);

                    resupplyCol.HeaderText = "Re-supply POR";
                    resupplyCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "resupply_por");
                    GV.Columns.Add(resupplyCol);

                    adtlMWCol.HeaderText = "Adtl MW's POR";
                    adtlMWCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "additional_mw");
                    GV.Columns.Add(adtlMWCol);

                    totalMWCol.HeaderText = "Total MW's POR";
                    totalMWCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "totalMW");
                    GV.Columns.Add(totalMWCol);

                    priceCol.HeaderText = "Price";
                    priceCol.ItemStyle.Width = Unit.Pixel(55);
                    priceCol.ItemTemplate = new AddGridviewTemplate(DataControlRowType.DataRow, "price");
                    GV.Columns.Add(priceCol);


                    coTypeId.HeaderText = "Call Option Type ID";
                    coTypeId.DataField = "call_option_type_id";
                    coTypeId.Visible = false;
                }
            }

            GV.DataSource = ds;
            GV.DataBind();
            PH.Controls.Add(GV);

        }

Open in new window

0
 

Author Closing Comment

by:bschave2
ID: 35460744
nobody commented and I figured out the solution on my own.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question