Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help! C#/ASP.NET/Dreamweaver

    Hello im very new here and thought this was a great website/forum to help me with my very fustrating question. I have 3 drop down boxes (example,stage1,stage2 ID's) a Add button(btnadd) and a label(lbldesc). The drop down box are arrays with multiple selections.. example...

    The dropdown boxes and selection:
    [example] [stage1] [stage2]
    1st selection [nike] [$100]
    [shoe] [shoe 2] [$200] [My Add Button]
    [shoe 3] [300]

    so on and so forth..


    let say I choose Shoe Nike that cost 100.00

    I have the Add button(btnadd) to post to the label on a form on the SAME page.

    Form below the dropdownbox

    description | Price
    ---------------------------------------------------
    Shoe Nike | 100.00
    (cmbostate + stage 2) | (stage 3)
    ---------------------------------------------------
    Total |100.00


    what is the easiest way to do this?
    here is some snippets of code that i took off my source.

    the event:
    <script runat="server">
    public void Page_Load(Object sender, EventArgs E) {
    }
    void btnAdd_Click(object sender, EventArgs e) {
    lbldesc.Text = cmbostate.Text; (Ill put the rest of the code was just trying to see if it worked with the first dropdownbox)
    }
    </script>

    my "add button":

    <asp:Button ID="btnAdd" Text="Add" runat="server" onclick="btnadd_Click"></asp:Button>

    my "label":
    <asp:Label ID="lbldesc" runat="server" />

    my combo box:
    cmbostate, stage 2, stage 3

    i get a strange error telling me that:
    error CS0246: The type or namespace name 'cmbostate' could not be found.


    Anyone who can help me is greatly appreciated. Thanks!

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Where is
    <form runat="server" ... ?

    To use postback, you must be using a web form.

    Oh, and
    cmbostate
    I think you wanted
    this.cmbostate
    or something.

    I use code behind pages, so not sure. But you have to reference that control. You can't just use a variable with the same name. Not sure how it works without code behind pages; I use VS.net and it just makes them that way. LOL

    / also a bit of a newbie to .net
    Last edited by nikkiH; 09-21-2005 at 07:18 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can you post your source im sure if you show me how to grab the text from a dropdownlist with a button and post it on a label I can figure it out. Thanks!

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I don't have exact sort of thing, but I have a datagrid with a button that changes a label...

    Code:
    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 cms_reports
    {
    	/// <summary>
    	/// Summary description for TestForm.
    	/// </summary>
    	public class TestForm : System.Web.UI.Page
    	{
    		protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
    		protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
    		protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
    		protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
    		protected System.Data.SqlClient.SqlConnection sqlConnection1;
    		protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
    		protected cms_reports.dsTest dsTest1;
    		protected System.Web.UI.WebControls.Label Label1;
    		protected System.Web.UI.WebControls.DataGrid DataGrid1;
    	
    		public void Button1_Click (object source, System.EventArgs e)
    		{
    			this.Label1.Text = "Clicked Button 1!";
    		}
    		public void Button2_Click (object source, System.EventArgs e)
    		{
    			this.Label1.Text = "Clicked Button 2!";
    		}
    
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			// Put user code to initialize the page here
    			this.sqlDataAdapter1.Fill(this.dsTest1);
    			this.DataGrid1.DataBind();
    		}
    
    		#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.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
    			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
    			this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
    			this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
    			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
    			this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
    			this.dsTest1 = new cms_reports.dsTest();
    			((System.ComponentModel.ISupportInitialize)(this.dsTest1)).BeginInit();
    			// 
    			// sqlSelectCommand1
    			// 
    			this.sqlSelectCommand1.CommandText = "" // removed for post here
    			this.sqlSelectCommand1.Connection = this.sqlConnection1;
    			// 
    			// sqlInsertCommand1
    			// 
    			this.sqlInsertCommand1.CommandText = ""; // removed for post here
    			this.sqlInsertCommand1.Connection = this.sqlConnection1;
    
    /* removed a bunch of sql stuff */
    	
    			this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
    			// 
    			// dsTest1
    			// 
    			this.dsTest1.DataSetName = "dsTest";
    			this.dsTest1.Locale = new System.Globalization.CultureInfo("en-US");
    			this.Load += new System.EventHandler(this.Page_Load);
    			((System.ComponentModel.ISupportInitialize)(this.dsTest1)).EndInit();
    
    		}
    		#endregion
    	}
    }
    and the .net web form code

    Code:
    <%@ Page language="c#" Codebehind="TestForm.aspx.cs" AutoEventWireup="false" Inherits="cms_reports.TestForm" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>TestForm</title>
    		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    		<meta name="CODE_LANGUAGE" Content="C#">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="FlowLayout">
    		<form id="Form1" method="post" runat="server">
    			<asp:Label id="Label1" runat="server" Width="184px">Label</asp:Label>
    			<asp:DataGrid id=DataGrid1 runat="server" DataSource="<%# dsTest1 %>" DataKeyField="id" DataMember="rpt_specs" AutoGenerateColumns="False">
    				<Columns>
    					<asp:BoundColumn DataField="office_code" SortExpression="office_code" ReadOnly="True" HeaderText="office_code"></asp:BoundColumn>
    					<asp:BoundColumn DataField="report_name" SortExpression="report_name" ReadOnly="True" HeaderText="report_name"></asp:BoundColumn>
    					<asp:TemplateColumn>
    						<ItemTemplate>
    							<asp:Button id="Button1" runat="server" Text="Button" onclick="Button1_Click"></asp:Button>
    						</ItemTemplate>
    						<EditItemTemplate>
    							<asp:Button id="Button2" runat="server" Text="Button" onclick="Button2_Click"></asp:Button>
    						</EditItemTemplate>
    					</asp:TemplateColumn>
    				</Columns>
    			</asp:DataGrid>
    		</form>
    	</body>
    </HTML>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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