EDN Admin
Well-known member
<img src="http://social.microsoft.com/Forums/getfile/1633/" alt="
I have here a dropdownlist and right now Im able to store the correct customerID to the database by letting the customerID for the Order to be int custID = ddl2.selectedindex + 1;
Im using it since the list are ordered by id which is the default but what I want to do is use a "Order by" either or first or last name but then there would be no way I would be able to get the correct custID.
Im using class that contains sql related methods
<pre>protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
sql.populateCustomer(DropDownList1);
sql.populateProducts2(DropDownList2);
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
textQuantity.Text = "1";
}
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
textPrice.Text = ((decimal)decimal.Parse(textProdPrice.Text) * int.Parse(textQuantity.Text)).ToString();
//Calendar1.SelectedDate = DateTime.Now;
dateTextBox.Text = DateTime.Now.ToShortDateString();
sql.getOrder(GridView1);
}[/code]
<pre>protected void Button1_Click(object sender, EventArgs e)
{
DateTime date = Calendar1.SelectedDate;
int quantity = int.Parse(textQuantity.Text);
decimal price = ((decimal)decimal.Parse(textProdPrice.Text) * int.Parse(textPrice.Text)); //decimal.Parse(textPrice.Text);
int custid = DropDownList1.SelectedIndex + 1;
int prodid = DropDownList2.SelectedIndex + 1;
sql.addNewOrder(date, quantity, price, custid, prodid);
sql.getOrder(GridView1);
}[/code]
<br/>
<span><span style="color:#660066 Here<span> are the methods inside of
<span><span style="color:#000088 my<span> <span><span style="color:#000088 class<span><span style="color:#666600 :
<span><span style="color:#666600
<pre>public DropDownList populateCustomer(DropDownList ddl)
{
string select = "Select Fname,Lname From CustomerInfo";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++ )
{
string firstname = dt.Rows[0].ToString();
string lastname = dt.Rows[1].ToString();
ddl.Items.Add(firstname + " " + lastname);
}
return ddl;
}[/code]
<pre>public void addNewOrder(DateTime Orderdate, int quantity, decimal price, int custid, int prodid )
{
connection = new SqlConnection(conString);
connection.Open();
string addProd = "Insert into OrderInfo Values (" + Orderdate + "," + quantity + ", " + price + ", " + custid + ", " + prodid + ") ";
command = new SqlCommand(addProd, connection);
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
connection.Dispose();
}[/code]
<br/>
<span><span style="color:#660066 Your<span><span style="color:#000000 answers would be of great help. Thank you.
<hr class="sig Randel Ramirez
View the full article
I have here a dropdownlist and right now Im able to store the correct customerID to the database by letting the customerID for the Order to be int custID = ddl2.selectedindex + 1;
Im using it since the list are ordered by id which is the default but what I want to do is use a "Order by" either or first or last name but then there would be no way I would be able to get the correct custID.
Im using class that contains sql related methods
<pre>protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
sql.populateCustomer(DropDownList1);
sql.populateProducts2(DropDownList2);
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
textQuantity.Text = "1";
}
textProdPrice.Text = sql.getProductPrice(DropDownList2.SelectedValue);
textPrice.Text = ((decimal)decimal.Parse(textProdPrice.Text) * int.Parse(textQuantity.Text)).ToString();
//Calendar1.SelectedDate = DateTime.Now;
dateTextBox.Text = DateTime.Now.ToShortDateString();
sql.getOrder(GridView1);
}[/code]
<pre>protected void Button1_Click(object sender, EventArgs e)
{
DateTime date = Calendar1.SelectedDate;
int quantity = int.Parse(textQuantity.Text);
decimal price = ((decimal)decimal.Parse(textProdPrice.Text) * int.Parse(textPrice.Text)); //decimal.Parse(textPrice.Text);
int custid = DropDownList1.SelectedIndex + 1;
int prodid = DropDownList2.SelectedIndex + 1;
sql.addNewOrder(date, quantity, price, custid, prodid);
sql.getOrder(GridView1);
}[/code]
<br/>
<span><span style="color:#660066 Here<span> are the methods inside of
<span><span style="color:#000088 my<span> <span><span style="color:#000088 class<span><span style="color:#666600 :
<span><span style="color:#666600
<pre>public DropDownList populateCustomer(DropDownList ddl)
{
string select = "Select Fname,Lname From CustomerInfo";
adapter = new SqlDataAdapter(select, conString);
dt = new DataTable();
adapter.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++ )
{
string firstname = dt.Rows[0].ToString();
string lastname = dt.Rows[1].ToString();
ddl.Items.Add(firstname + " " + lastname);
}
return ddl;
}[/code]
<pre>public void addNewOrder(DateTime Orderdate, int quantity, decimal price, int custid, int prodid )
{
connection = new SqlConnection(conString);
connection.Open();
string addProd = "Insert into OrderInfo Values (" + Orderdate + "," + quantity + ", " + price + ", " + custid + ", " + prodid + ") ";
command = new SqlCommand(addProd, connection);
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
connection.Dispose();
}[/code]
<br/>
<span><span style="color:#660066 Your<span><span style="color:#000000 answers would be of great help. Thank you.
<hr class="sig Randel Ramirez
View the full article