我这是个文章编辑初始化的时候的程序,两个DropDownList表示文章的分类,,但在这DropDownList的值跟我要编辑文章的值不对应,应该怎么做呢,什么SelectedValue,FindValue的方法都用了怎么都不行,有做过的给详细指点一下 private void databind()
{
string sql;
DataSet ds=new DataSet();
SqlConnection conn2=new SqlConnection();
string strConn=System.Configuration.ConfigurationSettings.AppSettings["connstr"];
conn2.ConnectionString=strConn;
conn2.Open();
sql="select * from info_type where sitename='sdcio' order by num";
ds=conn.GetDs(sql);
DropDownList3.DataSource=ds;
DropDownList3.DataBind(); sql="select * from info_dict where sitename='sdcio' and tab_type="+DropDownList3.SelectedValue+" order by num";
ds=conn.GetDs(sql);
DropDownList1.DataSource=ds;
DropDownList1.DataBind();
arcid=int.Parse(Request["aid"].ToString());
sql="select * from cio_arc where id="+Request["aid"];
SqlCommand cmd=new SqlCommand(sql,conn2);
SqlDataReader re=cmd.ExecuteReader();
re.Read();
TextBox1.Text=re["topic"].ToString();
TextBox3.Text=re["author"].ToString();
TextBox4.Text=re["source"].ToString();
FreeTextBox2.Text=re["content"].ToString();
re.Close();
conn2.Close();
}
{
string sql;
DataSet ds=new DataSet();
SqlConnection conn2=new SqlConnection();
string strConn=System.Configuration.ConfigurationSettings.AppSettings["connstr"];
conn2.ConnectionString=strConn;
conn2.Open();
sql="select * from info_type where sitename='sdcio' order by num";
ds=conn.GetDs(sql);
DropDownList3.DataSource=ds;
DropDownList3.DataBind(); sql="select * from info_dict where sitename='sdcio' and tab_type="+DropDownList3.SelectedValue+" order by num";
ds=conn.GetDs(sql);
DropDownList1.DataSource=ds;
DropDownList1.DataBind();
arcid=int.Parse(Request["aid"].ToString());
sql="select * from cio_arc where id="+Request["aid"];
SqlCommand cmd=new SqlCommand(sql,conn2);
SqlDataReader re=cmd.ExecuteReader();
re.Read();
TextBox1.Text=re["topic"].ToString();
TextBox3.Text=re["author"].ToString();
TextBox4.Text=re["source"].ToString();
FreeTextBox2.Text=re["content"].ToString();
re.Close();
conn2.Close();
}
解决方案 »
- .net与java通过rpc通信 .net这边该怎么写????
- 提问赶在下班前
- 空间服务商给我们的网站听了,说占用cpu使用率太大!如何解决?没有分了大家包含
- 花了两周的所有休息时间写了个客户管理系统,请大家帮我测试一下
- asp.net调用存储过程的困惑
- 望指教!Asp 回发的问题
- 分析器错误信息: 未能加载类型 ,什么原因??
- 本机调试没有问题 上传到服务器有问题
- 简单的判断问题,关于datagrid的/高手帮忙搞定!!!!!!!
- ajax怕刷新,谁懂?
- AjaxPro.2.dll在ASP.net2.0里怎样用?
- 關於Ajax的問題 在線等.請各位大俠申出援手(急急急急急急急急急急急急) 分不夠可以加
DropDownList3.SelectedValue 改为
DropDownList3.SelectedItem.Text 看看!
DropDownList1.DataTextField = ds.Tables[0].Columns["NAME"].ToString(); //绑定DropDownList1中每项的Text
DropDownList1.DataValueField = ds.Tables[0].Columns["NAME"].ToString();//绑定DropDownList1中每项的Value
DropDownList1.DataBind();DLqs.Items.Insert(0,"--请选择--");
DLqs.Items[0].Selected=true;
//绑定后再在DropDownList1的0索引处插入"--请选择--",注意顺序
DropDownList3.Items.FindByValue("27").Selected=true;,老是说:未将对象引用设置到对象的实例,郁闷啊
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(_table.Rows[0]["CatalogID"].ToString()));
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(_table.Rows[0]["CatalogID"].ToString()));以上语是根据条目的value来选中某一项的.如果这个value在DropDownList不存在,就会产生你说的那种情况,即返回未定义的值.