...

Help! C#/ASP.NET/Dreamweaver

Cpen
09-21-2005, 06:55 PM
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!

nikkiH
09-21-2005, 07:15 PM
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

Cpen
09-21-2005, 07:53 PM
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!

nikkiH
09-21-2005, 09:07 PM
I don't have exact sort of thing, but I have a datagrid with a button that changes a label...


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


<%@ 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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum