问题描述
基本上我在下拉列表中有两个面板控件。在这些面板中还有一个下拉列表。现在我可以从dropdownlist1输入数据到数据库。但是不知道如何从面板下的那些下拉列表输入数据到数据库。
请帮帮我....
这里是我的cs代码
protected void select_ctgry(object sender,EventArgs e)
{
if(DropDownList6.SelectedValue) .ToString()==豪华)
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = false;
}
else if(DropDownList7.SelectedItem.ToString()==SUV)
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
}
其他
{
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
}
}
protected void click_insert(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [carrental]。ConnectionString);
SqlCommand cmd = new SqlCommand();
尝试
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText =插入car_insert(城市,loc,c_type,电子邮件,日期,时间)值(@ city,@ loc,@ c_type,@ email,@ date,@ time);
cmd.Parameters.AddWithValue(@ city,DropDownList1.SelectedItem.Text.ToString());
cmd.Parameters。 AddWithValue(@ loc,DropDownList2.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue(@ loc,DropD ownList3.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue(@ c_type,DropDownList5.SelectedItem.Text.ToString());
cmd .Parameters.AddWithValue(@ email,TextBox2.Text.ToString());
cmd.Parameters.AddWithValue(@ time,DropDownList4.SelectedItem.Text.ToString());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
回复.Redirect(showdata.aspx);
}
catch(exception ex)
{Response.Write(ex.Message); }
}
}
}
Basically i have two panel control under a dropdownlist.within those panel also have a dropdownlist. now i can enter the data from dropdownlist1 to database. But don't know how to enter data from those dropdownlist under panel into database.
please help me....
here's my cs code
protected void select_ctgry(object sender, EventArgs e)
{
if (DropDownList6.SelectedValue.ToString() == "Luxury")
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = false;
}
else if (DropDownList7.SelectedItem.ToString() == "SUV")
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
}
else
{
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
}
}
protected void click_insert(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["carrental"].ConnectionString);
SqlCommand cmd = new SqlCommand();
try
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into car_insert (city,loc,c_type,email,date,time) values(@city,@loc,@c_type,@email,@date,@time)";
cmd.Parameters.AddWithValue("@city", DropDownList1.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue("@loc", DropDownList2.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue("@loc",DropDownList3.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue("@c_type", DropDownList5.SelectedItem.Text.ToString());
cmd.Parameters.AddWithValue("@email", TextBox2.Text.ToString());
cmd.Parameters.AddWithValue("@time",DropDownList4.SelectedItem.Text.ToString());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("showdata.aspx");
}
catch (Exception ex)
{ Response.Write(ex.Message); }
}
}
}
推荐答案
这篇关于从dropdownlist的面板到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!