明白你的意思了:用A=dropdownlist.selecteditem.Value; Insert Into tablename (field) Values (dropdownlist.selecteditem.Value) 另外,在执行c的时候要执行两条insert命令。产生的问题用如下方法解决: DropDownList.Item(x) X:是下拉菜单的下标,可以表示物理位置。
首先dropdownlist的postback=true Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged if dropdownlist1.selecteditem.text="a" ...数据库里插入一条a的数据 end if if dropdownlist1.selecteditem.text="b" ...数据库里插入一条b的数据 end if if dropdownlist1.selecteditem.text="all" ...数据库里插入两条的数据 end ifEnd Sub
我是新手,我也知道应该是这样 if dropdownlist1.selecteditem.text="all" ...数据库里插入两条的数据 end if 但我怎么取得dropdownlist1里边所有的值 还有 ponycsdn(驰骏)大哥说的DropDownList.Item(x) 这个x是动态生成的,在接受端是不是要用个数组什么的 给断代码好吗
foreach(ListItem item in DropDownList1.Items) { Response.Write(item.Value); }
他可能会有10各选想也可能有5各选想
正常情况下只有选择a或者b进行插入数据动作
但是现在需要一个全选的功能,以选择全选就把这10条或者5条选想都插入数据库里
Insert Into tablename (field) Values (dropdownlist.selecteditem.Value)
另外,在执行c的时候要执行两条insert命令。产生的问题用如下方法解决:
DropDownList.Item(x) X:是下拉菜单的下标,可以表示物理位置。
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
if dropdownlist1.selecteditem.text="a"
...数据库里插入一条a的数据
end if
if dropdownlist1.selecteditem.text="b"
...数据库里插入一条b的数据
end if
if dropdownlist1.selecteditem.text="all"
...数据库里插入两条的数据
end ifEnd Sub
if dropdownlist1.selecteditem.text="all"
...数据库里插入两条的数据
end if
但我怎么取得dropdownlist1里边所有的值
还有 ponycsdn(驰骏)大哥说的DropDownList.Item(x)
这个x是动态生成的,在接受端是不是要用个数组什么的
给断代码好吗
{
Response.Write(item.Value);
}
如果你真的不知道,那只有foreach遍历一下dropdownlist里的所有选项,一个一个来咯
if (ddlGM.SelectedItem.Value=="all")
{
if(gmt.Add(string[] ddlGM.Items.ToString()))
{
Response.Write("<Script Language=JavaScript>");
Response.Write("alert('添加成功!');document.location.href='GMTerm.aspx'");
Response.Write("</Script>");
}
}
public bool Add(string[] allUserId)
{
string[] temp = userId.Split(",");
try
{
for(int i = 0; i < temp.Length; i++)
{
sql=Insert Into tablename (field) Values (temp[i])
}
}
}
可是好像总是有问题请教
foreach(ListItem item in DropDownList1.Items) {
if(item.Value != "all") {
Add(item.Value);
}
}
}
else {
Add(ddlGM.SelectedItem.Value);
}public bool Add(strUserId) {
try {
strSql=INSERT INTO tablename (field) VALUES (strUserId);
}
}大概就是这个意思了