dropdownlist
我想问一下!!我做了个修改的页面。想把在数据中的数据放在dropdownlist中。然后要修改这个时,让dropdownlist在重新绑定数据库中的某个列改怎么做--------------------编程问答-------------------- 坦白说 我没看懂~~~~~~~~~~~~~ --------------------编程问答-------------------- 没明白. --------------------编程问答-------------------- DropDownList.DataSource=DataSet1;//这个DataSet1就是你从数据库取出来的数据集
DropDownList.DataTextField="数据库中字段1";
DropDownList.DataValueField="这个一般是ID之类的字段,不写的话默认和TextField相同";
DropDownList.DataBind();
如果想改变他绑定的数据源,只需改变DataSource及他的DataTextField等就行了。
--------------------编程问答-------------------- 坦白说,1楼很直接。2楼很坦白,3楼也一样~ --------------------编程问答-------------------- 不明白LZ要表达的意思 --------------------编程问答-------------------- using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["NAME"].ToString() == null || Session["NAME"].ToString() == "")
{
Response.Redirect("../ErrorPage.aspx?ErrorUrl=AddRKD.aspx&ErrorMsg=请登录");
}
else
{
if (!IsPostBack)
{
this.DPbangding();
this.getvale();
}
}
}
private void getvale()
{
string sql = "select * from RKD where ID=" + Session["ID1"];
SqlDataReader dr = config.read(sql);
if (dr.Read())
{
this.TextBox1.Text = dr["PJID"].ToString();
this.TextBox2.Text = dr["GFNAME"].ToString();
this.TextBox3.Text = dr["HWNAME"].ToString();
//this.DropDownList1.SelectedValue = dr["LB"].ToString();
this.DropDownList1.SelectedIndex = this.DropDownList1.Items.IndexOf(this.DropDownList1.Items.FindByValue(dr["LB"].ToString()));
this.TextBox4.Text = dr["GG"].ToString();
this.TextBox5.Text = dr["SL"].ToString();
this.TextBox6.Text = dr["DJ"].ToString();
this.TextBox7.Text = dr["ZJ"].ToString();
this.DropDownList2.SelectedValue = dr["FF"].ToString();
this.TextBox12.Text = dr["KFH"].ToString();
this.TextBox13.Text = dr["ZHH"].ToString();
this.TextBox9.Text=dr["SHR"].ToString();
this.TextBox11.Text = dr["JSR"].ToString();
this.TextBox10.Text = dr["BZH"].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("DGRKD.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "update RKD set PJID='" + this.TextBox1.Text.ToString().Trim() + "',GFNAME='" + this.TextBox2.Text.ToString().Trim() + "',HWNAME='" + this.TextBox3.Text.ToString().Trim() + "',LB='" + this.DropDownList1.SelectedValue.ToString() + "',GG='" + this.TextBox4.Text.ToString().Trim() + "',SL='" + this.TextBox5.Text.ToString().Trim() + "',DJ='" + this.TextBox6.Text.ToString().Trim() + "',ZJ='" + this.TextBox7.Text.ToString().Trim() + "',FF='" + this.DropDownList2.SelectedValue.ToString() + "',KFH='" + this.TextBox12.Text.ToString().Trim() + "',ZHH='" + this.TextBox13.Text.ToString().Trim() + "',SHR='" + this.TextBox9.Text.ToString().Trim() + "',JSR='"+this.TextBox11.Text.ToString().Trim()+"',BZH='"+this.TextBox10.Text.ToString().Trim()+"' where ID="+Session["ID1"];
int i = config.execsql(sql);
if (i == 1)
{
Response.Write("<script language=javascript>alert('更新成功');</script>");
}
else
{
Response.Write("<script language=javascript>alert('更新失败')</script>");
}
}
private void DPbangding()
{
string sql = "select * from SYSL";
DataSet ds = config.getgrid(sql);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
this.DropDownList1.DataValueField = "LB";
this.DropDownList1.DataBind();
}
}
--------------------编程问答-------------------- 这是我的代码看看写的哪里有错误
--------------------编程问答-------------------- 眼睛有问题看不出来,自己调示,看哪里出错了就哪里有问题了! --------------------编程问答-------------------- 一、未关闭数据库
private void getvale()方法里,你用了
SqlDataReader dr = config.read(sql);
if (dr.Read())
但,函数结束前,你未关闭数据库
结束前请关闭数据库
只看出这一点
补充:.NET技术 , ASP.NET