
方式1:使用Strust1标签--html:select
方式2:使用Strust2标签--s:select
方式3:ext框架--ExtformComboBox
方式4:在页面获取
结果集
(表查询结果),使用循环迭代方式(jstl
el语言或页面嵌入java代码或js实现),循环处理结果集,增加select控件元素
注:我没有详细说明,但是只要搜索相关的方式,很容易明白具体实现。
表、字段的处理最好都在业务层处理完结果集,再传到前台页面处理,既符合mvc并且调试和维护都方便。
string mateSql = "select L1,L2,inv_code,material from inv_master where isvisible='Y' order by L0,L1,L2";
SqlDataAdapter mateDa = new SqlDataAdapter(mateSql, myConncon);
DataSet mateDs = new DataSet();
mateDaFill(mateDs);
ListItem mateLI;
string mate = "";
for (int i = 0; i < mateDsTables[0]RowsCount; i++)
{
DataRowView matedrv = mateDsTables[0]DefaultView[i];
mateLI = new ListItem(mate, matedrv["inv_code"]ToString()Trim());
selectMateItemsAdd(mateLI);
}
}
添加选项的话
dropdrowlistitemsadd(text,value)
下面再加绑定数据库
定义重名了吧,重新定义个
if (category != null)
{
ViewData["MyCategory"] = new SelectList(categories, "CategoryId", "Name", categoryCategoryId);
}
else
{
ViewData["MyCategory"] = new SelectList(categories, "CategoryId", "Name");
}
private void Form1_Load(object sender, EventArgs e)
{
String ConnectionString = "Server=\\mysqlserver;DataBase=demo;uid=sa;pwd=songhai111";
SqlConnection Connection = new SqlConnection(ConnectionString);//声明数据库链接
string SqlString = "select name from test order by id desc";//查询语句
DataSet dataset = new DataSet();//声明数据集
ConnectionOpen(); //打开数据库
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, Connection);
adapterFill(dataset);//读取数据放入数据集
ConnectionClose();//关闭数据库
DataTable dt = datasetTables[0]; //从数据集中取出表
comboBox1DataSource = dt;//下拉列表绑定查询的10条的数据表
comboBox1DisplayMember = "name";//设置下拉显示的是month行的值
comboBox1SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1Text = (comboBox1SelectedValue)ToString();
string txt = thiscomboBox1Text;
thistextBox1Text = txt;
}
}
其它功能你自己看着弄就行了
以上就是关于JSP页面中,怎样在一个下拉框选项中绑定数据库表字段 表名DeviceManage 字段:DEVICETYPE全部的内容,包括:JSP页面中,怎样在一个下拉框选项中绑定数据库表字段 表名DeviceManage 字段:DEVICETYPE、c#中下拉列表如何与数据库绑定 用代码实现、.net MVC使用一个下拉框 ,Html.DropDownList出错等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)