添加不了新行?why? 为什么不用DisplayMember和ValueMember? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谁能告诉错在哪了??? 这两段代码没有实际的关联,是独立的! 在第一段中我是想用DataView来增加新行的 在第二段中我是想用DataRow来增加新行的 通过select查出的数据,我是想把它绑定在下拉列表框中显示的, 增加的新行并不在数据库中,也不需要保存到数据库,只是显示的时候,让它显示 通常在要下拉列表框中“请选择”的,我就是想在显示是多一个“请选择” it works for me:<%@ Import Namespace="System.Data.SqlClient"%><%@ Import Namespace="System.Data"%><form runat="server"><asp:DropDownList id="DropDownList1" runat="server"/><BR><asp:DropDownList id="DropDownList2" runat="server" /></form><script language="C#" runat="server">const string sConn = "Server=localhost;Database=pubs;UID=sa;PWD=;";void Page_Load(Object o, EventArgs e){ if (!IsPostBack) { SqlDataAdapter da = new SqlDataAdapter("select * from authors", sConn); DataSet ds = new DataSet(); da.Fill(ds,"authors"); da.Fill(ds,"authors2"); DataView dv = new DataView(ds.Tables["authors"]); DataRowView drv = dv.AddNew(); drv["au_lname"] = "aaaaaaaaaaaaa"; //drv.EndEdit(); DropDownList1.DataSource = dv; DropDownList1.DataTextField = "au_lname"; DropDownList1.DataValueField = "au_id"; DropDownList1.DataBind(); DataView dv2 = new DataView(ds.Tables["authors2"]); DataRow dr = ds.Tables["authors2"].NewRow(); dr["au_lname"] = "bbbbbbbbbbbbbbb"; ds.Tables["authors2"].Rows.Add(dr); DropDownList2.DataSource = dv2; DropDownList2.DataTextField = "au_lname"; DropDownList2.DataValueField = "au_id"; DropDownList2.DataBind(); }}</script> 水晶报表用针式打印机打印走纸控制问题,急!!!急!!!急!!!请帮顶,这个问题困扰了很多人 winform中怎么设置默认焦点在一个textbox上 C# web 页面上 做一个播放视频文件的进度条?? 急!!!突然找出现找不到服务器,网络连接是正常的 急!表单提交问题 关于应用c#winform中打开指定的地址的网页问题! C++程序设计题 C# modbus numberof regisers 继承的用户控件触发事件问题【狂简单】 datagrid控件能不能用来显示任意的数据啊?? 公司要求员工持股,在下征求一下大家的意见。 关于DropDownList与从数据库中调用的数据匹配问题?
这两段代码没有实际的关联,是独立的! 在第一段中我是想用DataView来增加新行的
在第二段中我是想用DataRow来增加新行的 通过select查出的数据,我是想把它绑定在下拉列表框中显示的,
增加的新行并不在数据库中,也不需要保存到数据库,只是显示的时候,让它显示
通常在要下拉列表框中“请选择”的,我就是想在显示是多一个“请选择”
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Data"%>
<form runat="server">
<asp:DropDownList id="DropDownList1" runat="server"/><BR>
<asp:DropDownList id="DropDownList2" runat="server" />
</form>
<script language="C#" runat="server">
const string sConn = "Server=localhost;Database=pubs;UID=sa;PWD=;";
void Page_Load(Object o, EventArgs e)
{
if (!IsPostBack)
{
SqlDataAdapter da = new SqlDataAdapter("select * from authors", sConn);
DataSet ds = new DataSet();
da.Fill(ds,"authors");
da.Fill(ds,"authors2"); DataView dv = new DataView(ds.Tables["authors"]); DataRowView drv = dv.AddNew();
drv["au_lname"] = "aaaaaaaaaaaaa";
//drv.EndEdit(); DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "au_lname";
DropDownList1.DataValueField = "au_id";
DropDownList1.DataBind(); DataView dv2 = new DataView(ds.Tables["authors2"]); DataRow dr = ds.Tables["authors2"].NewRow();
dr["au_lname"] = "bbbbbbbbbbbbbbb";
ds.Tables["authors2"].Rows.Add(dr); DropDownList2.DataSource = dv2;
DropDownList2.DataTextField = "au_lname";
DropDownList2.DataValueField = "au_id";
DropDownList2.DataBind();
}
}</script>