C# 中 DropDownList 如何数据绑定 数据库里某一表里的一个字段的值 先边userid主键读出来就可以update了,哈哈…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 去Microsoft quickstart 看看,很多新手的例子http://chs.gotdotnet.com/quickstart/default.aspx 先根据userid获取数据,修改后再根据userid更新 通过你的userid update.在你点按钮的时候.. aspx代码(sex=1为男,sex=0为女) <asp:TextBox ID="txtname" runat="server" Width="140px"></asp:TextBox> <asp:DropDownList ID="ddlsex" runat="server" DataValueField="sex " OnSelectedIndexChanged="ddlParentCategory_SelectedIndexChanged" AutoPostBack="True"> </asp:DropDownList>cs文件(现将用户的基本信息取出放在一个dataset里边ds)txtname.Text = ds.tables[0].rows[0]["name"].ToString();ddlManufacture.SelectedValue = ds.tables[0].rows[0]["sex "].ToString();点击button出发的事件 dropdownlist控件写在aspx里<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem Value="0" Selected="True">男</asp:ListItem> <asp:ListItem Value="1">女</asp:ListItem> </asp:DropDownList>button1的click事件里string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(constr);SqlCommand comm = new SqlCommand("insert into people (name,sex)values(@name,@sex)",coon);comm.Parameters.Add("name", SqlDbType.VarChar, 20); comm.Parameters["name"].Value = TextBox1.Text;comm.Parameters.Add("Sex", SqlDbType.Int, 4); comm.Parameters["Sex"].Value = DropDownList1.SelectdItem.Text; 取出来 绑定 一下 ,直接UPDATE 就可以了 str sql="select * from people where userid ='"+ id+"'";SqlDataReader sdr = dot.getRow(sql);sdr.read();textBox1.text=sdr["name"].ToString();string name=textbox1.text;string sex=DROPDOWENLIST1.text;string sql1="UPDATE people set name='"+name+"' ,sex='"+sex+"' where userid='"+id+"'"; if(DOT.execSQL(sql1)){ 成功}else{ 失败} SQL多音词汉字转拼音 这段代码有什么问题,为什么GridView不能显示呢? 问大家一个非常专业的问题,在线等!!!!急急急!!!! 线程更新DataGridView的内容,DataGridView不显示 了。 求UDP多客户端访问安全通讯方式 一个C#测试题 ,希望高手来解答 100分求C#代码,急~~~ C#中两个树,左边树节点被点中运行数据库查询,想要知道点击左数节点的事件是什么,怎么写? 自绘求助... 急急!!打印报表问题!! dataset加入两张表了,为何用WriteXml,只能输出第一张表的数据? 请教一下各位大侠!如何使用代码调整dataGridView单元格的大小!
http://chs.gotdotnet.com/quickstart/default.aspx
<asp:TextBox ID="txtname" runat="server" Width="140px"></asp:TextBox>
<asp:DropDownList ID="ddlsex" runat="server" DataValueField="sex " OnSelectedIndexChanged="ddlParentCategory_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
cs文件
(现将用户的基本信息取出放在一个dataset里边ds)
txtname.Text = ds.tables[0].rows[0]["name"].ToString();
ddlManufacture.SelectedValue = ds.tables[0].rows[0]["sex "].ToString();
点击button出发的事件
<asp:ListItem Value="0" Selected="True">男</asp:ListItem>
<asp:ListItem Value="1">女</asp:ListItem>
</asp:DropDownList>button1的click事件里string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(constr);
SqlCommand comm = new SqlCommand("insert into people (name,sex)values(@name,@sex)",coon);
comm.Parameters.Add("name", SqlDbType.VarChar, 20);
comm.Parameters["name"].Value = TextBox1.Text;
comm.Parameters.Add("Sex", SqlDbType.Int, 4);
comm.Parameters["Sex"].Value = DropDownList1.SelectdItem.Text;
sdr.read();
textBox1.text=sdr["name"].ToString();
string name=textbox1.text;
string sex=DROPDOWENLIST1.text;
string sql1="UPDATE people set name='"+name+"' ,sex='"+sex+"' where userid='"+id+"'";
if(DOT.execSQL(sql1))
{
成功
}
else
{
失败
}