[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/14/2007 at 02:37PM PDT, ID: 22450178
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Duplicate data coming into ASP.NET 2.0 GridView on DataBind

Asked by DanielBorson in Programming for ASP.NET, Microsoft Development, .Net Editors & IDEs

Tags: boundfield, duplicate, gridview, columns

I have an ASP.NET 2.0 web form that includes a GridView control. I then have a method in the code-behind that loads the results of an SQL stored procedure into an SQLDataReader and binds it to the GridView control. In the GridView control, I've set the columns using mostly bound fields. The GridView is displaying the columns correctly, but then it goes ahead and adds extra columns, one for each column returned by the stored procedure. What's going on, and how can I get it to return only those columns that I have specifically designated inside the <Columns> tag?

Here's the ASP.NET code for the GridView:

          <asp:GridView ID="gvPlanList" ShowHeader="true" ShowFooter="false"  RowStyle-BorderStyle="none"
                    HeaderStyle-BackColor="LightBlue"
                    RowStyle-Font-Size="10px"
                    HeaderStyle-Font-Size="10px"
                    HeaderStyle-Font-Bold="true"
                    AllowPaging="false"
                    runat="server"
          >
            <Columns>
               
                    <asp:ButtonField Text="Add" CommandName="AddPlanToMyQuote" HeaderText="My Quote" HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="White" />
                    <asp:BoundField DataField="Rate1" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderText="Employee Only" />
                    <asp:BoundField DataField="Rate2" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderText="Employee + Spouse" />
                    <asp:BoundField DataField="Rate3" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderText="Employee + Family" />
                    <asp:BoundField DataField="Rate4" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderText="Employee +Children" />
                    <asp:BoundField DataField="Total" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderText="Total Premium" />
                    <asp:BoundField DataField="Total" DataFormatString="{0:c}" HeaderStyle-BackColor="LightBlue" HeaderStyle-ForeColor="#990000" HeaderText="Employer Contribution" />
                    <asp:TemplateField ItemStyle-Width="40" HeaderStyle-BackColor="White" HeaderStyle-ForeColor="White" HeaderText="" />
                    <asp:HyperlinkField Text="PlanProfile" DataNavigateUrlFields="plandetails.htm?plan={1}"  HeaderStyle-BackColor="LightBlue" HeaderText="Quoted Plan<br />(Click plan to view details)" />

            </Columns>
       
        </asp:GridView>

And here's the code-behind method being called:

    public void getData()
    {
        SqlConnection conn = new SqlConnection(_dbConnection);
        conn.Open();
        try
        {
                    SqlCommand command = new SqlCommand("ITDB.dbo.spSOMCAgentWebQuote_sel", conn);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@ProposalID", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@RatepageCategoryID", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@EECount", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@ESCount", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@EFCount", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@ECCount", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@EmployerContributionID", SqlDbType.Int));
                    command.Parameters[0].Value = _proposalID;
                    command.Parameters[1].Value = _ratepageCategoryID;
                    command.Parameters[2].Value = _eeCount;
                    command.Parameters[3].Value = _esCount;
                    command.Parameters[4].Value = _efCount;
                    command.Parameters[5].Value = _ecCount;
                    command.Parameters[6].Value = _employerContributionID;

                    SqlDataReader dataReader = command.ExecuteReader();

                    dataReader.Read();

                    this.gvPlanList.DataSource = dataReader;
                    this.gvPlanList.DataBind();

        }
        catch {
        }
        finally
        {
            conn.Close();
        }
    }
 
Loading Advertisement...
 
[+][-]03/14/07 02:47 PM, ID: 18722579

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, Microsoft Development, .Net Editors & IDEs
Tags: boundfield, duplicate, gridview, columns
Sign Up Now!
Solution Provided By: ullfindsmit
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03/14/07 07:08 PM, ID: 18724126

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/19/07 10:41 AM, ID: 18750003

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74