Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2006, 06:23 AM
Registered User
 
Join Date: Oct 2006
Location: Lightwater, Surrey, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically add buttons to dataGrid in a placehold

Hi,

I have a form with a place holder.
Using c# I am looking to add two datagrids dynamically (both with a button in) and 2 labels.

I have this working fine... although I haven't set my second button to do anything yet..

My problem is I cannot get my second button to appear on the right rather than the left.

Here is my .cs code.. Can you help

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MetroTravelCentre
{
    /// <summary>
    /// Summary description for cms_view.
    /// </summary>
    public class cms_view : System.Web.UI.Page
    {
        protected SVNet.SVNet SVNet = new MetroTravelCentre.SVNet.SVNet();
        protected System.Web.UI.WebControls.Label lblMetroID;
        protected System.Web.UI.WebControls.Label lblTransactionID;
        protected System.Web.UI.WebControls.Button cmdNewSearch;
        protected System.Web.UI.WebControls.Button cmdBack;
        protected System.Web.UI.WebControls.PlaceHolder PlaceHolder;

        private void Page_Load(object sender, System.EventArgs e)
        {

                System.Web.UI.WebControls.Label lblViewDetails = new System.Web.UI.WebControls.Label();
                System.Web.UI.WebControls.Label lblSalesHistory = new System.Web.UI.WebControls.Label();
                System.Web.UI.WebControls.Label lblMetroID = new System.Web.UI.WebControls.Label();
                System.Web.UI.WebControls.Label lblTransactionID = new System.Web.UI.WebControls.Label();

                lblViewDetails.Text = "Personal Details";
                lblViewDetails.Font.Bold = true;
                lblSalesHistory.Text = "Sales History";
                lblSalesHistory.Font.Bold = true;



                string sMetroID = Request.QueryString["CRMID"];
                this.lblMetroID.Text = sMetroID;
                string sTransactionID = Request.QueryString["TransactionID"];
                this.lblTransactionID.Text = sTransactionID;


                PlaceHolder.Controls.Add(lblViewDetails);

                System.Web.UI.WebControls.DataGrid dgdCustomerDetails = new System.Web.UI.WebControls.DataGrid();

                FormatGrid(dgdCustomerDetails);


                ButtonColumn amendcol = new ButtonColumn();
                amendcol.ButtonType = ButtonColumnType.PushButton;
                amendcol.Text = "Amend";
                amendcol.CommandName = "Edit";
                dgdCustomerDetails.Columns.Add(amendcol);

                //add event handler
                dgdCustomerDetails.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(dgdCustomerDetails_ItemCommand);

                dgdCustomerDetails.SelectedItemStyle.ForeColor = System.Drawing.Color.Blue;

                DataSet dsCustomerDetails = SVNet.f_tc_viewcustomer("12345",sMetroID,"VIEW");

                dgdCustomerDetails.DataSource=dsCustomerDetails;
                dgdCustomerDetails.DataBind();

                PlaceHolder.Controls.Add(dgdCustomerDetails);

                PlaceHolder.Controls.Add(lblSalesHistory);

                System.Web.UI.WebControls.DataGrid dgdSalesHistory = new System.Web.UI.WebControls.DataGrid();
                FormatGrid(dgdSalesHistory);

                DataSet dsSalesHistory = SVNet.f_tc_viewsales("12345",sMetroID);
                dgdSalesHistory.DataSource=dsSalesHistory;

                ButtonColumn Surrendercol = new ButtonColumn();
                Surrendercol.ButtonType = ButtonColumnType.PushButton;
                Surrendercol.Text = "Surrender";
                Surrendercol.CommandName = "Surrender";

                dgdSalesHistory.Columns.Add(Surrendercol);

                dgdSalesHistory.DataBind();
                PlaceHolder.Controls.Add(dgdSalesHistory);

        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cmdNewSearch.Click += new System.EventHandler(this.cmdNewSearch_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void dgdCustomerDetails_ItemCommand(object sender, DataGridCommandEventArgs e)
        {
            string sButton =e.CommandName;

            switch(sButton)
            {
                case "Edit":
                    //Amend Customer Details
                    Response.Redirect("cms_edit.aspx?MODE=EDIT&CRMID=" + this.lblMetroID.Text +
                        "&TransactionID=" + this.lblTransactionID.Text);
                    break;
            }
        }
        private void FormatGrid(System.Web.UI.WebControls.DataGrid dgdGridName)
        {
            dgdGridName.Width = 700;
            dgdGridName.Height= 100;
            dgdGridName.GridLines = GridLines.Both;
            dgdGridName.CellSpacing = 2;
            dgdGridName.CellPadding = 4;
            dgdGridName.ForeColor=System.Drawing.Color.Black;
            dgdGridName.HeaderStyle.BackColor = System.Drawing.Color.Black;
            dgdGridName.HeaderStyle.ForeColor = System.Drawing.Color.White;
            dgdGridName.HeaderStyle.Font.Bold = true;
            dgdGridName.BorderStyle = BorderStyle.Solid;
            dgdGridName.BorderWidth = 3;
            dgdGridName.BorderColor = System.Drawing.Color.DarkGray;
            dgdGridName.FooterStyle.BackColor = System.Drawing.Color.LightGray;
            dgdGridName.ItemStyle.BackColor = System.Drawing.Color.White;
        }

        private void cmdNewSearch_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("cms_search.aspx?TransactionID=" + this.lblTransactionID.Text);
        }

    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
How add data into DataGrid dynamically AccessAasif@aol.com C# 2005 1 October 24th, 2007 03:27 AM
create buttons dynamically on webpage rocksbhavesh ASP.NET 1.0 and 1.1 Professional 5 April 19th, 2007 05:20 PM
Dynamically added panel with radio buttons ADM10 Visual Basic 2005 Basics 1 May 11th, 2006 10:27 PM
Problem with dynamically rendered radio buttons daddyunit Javascript 1 January 19th, 2006 04:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.