Results 1 to 8 of 8

Thread: [RESOLVED] Gridview bound column issue

Threaded View

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Resolved [RESOLVED] Gridview bound column issue

    Hi All,
    I am trying to create a bound column and bind the data with the below piece of code . And the column has two files Name and Fee but the code binds only the Fees column and Name column become empty.. Any idea ?

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        
        
        protected void Page_Load(object sender, EventArgs e)
        {
          if (!Page.IsPostBack)
          {
            // BuildColumnsDynamically is called in InitializeComponent method
            BuildColumnsDynamically();
    
          }
        }
    
        private void BuildColumnsDynamically()
        {
            BoundField nameColumn = new BoundField();
            nameColumn.DataField = "Name";
            nameColumn.HeaderText = "Person Name";
    
            BoundField feecolumn = new BoundField();
            nameColumn.DataField = "Fee";
            nameColumn.HeaderText = "Fees";
                 
            GridView1.Columns.Insert(0,nameColumn);
            GridView1.Columns.Insert(1,feecolumn);
            FillGridView();
            
    
    
        }
    
        private void FillGridView()
        {
          int[] ids = { 12, 13, 14, 15, 16 };
          string[] names = { "Alice", "James", "Peter", "Simon", "David" };
          int[] fee = { 2299, 5123, 7564, 9595, 1600 };
          decimal[] prices = { 12.99m, 122.23m, 25.64m, 66.85m, 1.60m };
          decimal[] discounts = { 0.2m, 0.194m, 0.4564m, 0.209m, 0.310m };
          decimal[] differences = { -12m, 19.4m, -45.64m, 200.9m, 41.60m };
          string[] dates = { "04-12-2010", "07-23-2010", "07-14-2009", "12-12-2010", "11-03-2019" };
          bool[] onSale = { true, false, true, true, false };
    
          DataTable table = new DataTable();
          table.Columns.Add("Name", typeof(System.String));
          table.Columns.Add("Fee", typeof(System.Decimal));
    
          for (int i = 0; i < 5; i++)
          {
            DataRow row = table.NewRow();
    
            row["Name"] = names[i];
            row["Fee"] = fee[i];
    
            table.Rows.Add(row);
          }
    
          GridView1.DataSource = table;
          GridView1.DataBind();
    
          GridView1.UseAccessibleHeader = true;
          GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    
        private void InitializeComponent()
        {
          this.Init += new System.EventHandler(this._Default_Init);
          this.Load += new System.EventHandler(this.Page_Load);
          
    
        }
    
        private void _Default_Init(object sender, EventArgs e)
        {
          InitializeComponent();
          base.OnInit(e);
        }
    }
    
    
    Design Part
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
          th
          {
            cursor:pointer;
            background-color:#dadada;
            color:Black;
            font-weight:bold;
            text-align:left;
          }
          th.headerSortUp
          {     
            background-image: url(images/asc.gif);
            background-position: right center;
            background-repeat:no-repeat;
          }
          th.headerSortDown
          {     
            background-image: url(images/desc.gif);  
            background-position: right center;
            background-repeat:no-repeat;
          }
          td
          {
            border-bottom: solid 1px #dadada;   
          }
        </style>
    
        <script src="scripts/jquery-1.4.3.min.js" type="text/javascript"></script>
    
        <script src="scripts/jquery.tablesorter.min.js" type="text/javascript"></script>
    
        <script type="text/javascript">
          $(document).ready(function() {
            $("#GridView1").tablesorter();
          });
        </script>
        
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          
        
        </div>
          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
           >
          </asp:GridView>
        </form>
    </body>
    </html>
    Attached Files Attached Files
    Last edited by danasegarane; Jul 11th, 2011 at 03:33 AM. Reason: Attachment added
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width