判断语句问题!请大家来看看呀帮帮忙!顶这有分!各抒己见!
DropDownList判断显示问题!
绑定DropDownList 表名称 cnat_name
cnat_name表中是人名格式如下:
par_id par_lhb
1 小王
2 小嘎
3 哈哈
4 嘿嘿
在绑定的时候:
this.par_jayname.Items.Insert(0,new ListItem( "—请选校对人— ", "-1 "));
我加上了一段着个!
在显示的时候比方说数据库中“AutoPfed”这个字段是 <null> 我就想让它自动返回
这句 this.par_jayname.Items.Insert(0,new ListItem( "—请选校对人— ", "-1 "));
应该如何判断:这样不管用呀!
if( par_jayname.SelectedItem.Text == null )
{
this.par_jayname.Items.Insert(0,new ListItem( "—请选校对人— ", "-1 "));
}
else
{
this.par_jayname.SelectedItem.Text = dt.Rows[0][ "AutoPfed "].ToString();
}
代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlConnection con = DataCon.AutoCon();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from cnat_name ",con);
SqlDataReader sdr = cmd.ExecuteReader();
this.par_jayname.DataSource = sdr;
this.par_jayname.DataTextField = "par_lhb ";
this.par_jayname.DataValueField = "par_id ";
this.par_jayname.DataBind();
this.par_jayname.Items.Insert(0,new ListItem( "—请选校对人— ", "-1 "));
sdr.Close();
SqlDataAdapter sdz = new SqlDataAdapter( "cheParameter_GetList " + AutoID,con);
DataTable dt = new DataTable();
sdz.Fill(dt);
if(dt.Rows.Count == 0)
{
Response.Redirect( "http://localhost/AutoData/Errorjay.htm ");
return;
}
this.par_57.Text = dt.Rows[0][ "AutoMistake "].ToString();
this.par_jayname.SelectedItem.Text = dt.Rows[0][ "AutoPfed "].ToString();
con.Close();
}
------解决方案--------------------顶一下。
------解决方案--------------------showrock似乎没看清楚lz的要求
this.par_jayname.SelectedItem.Text = dt.Rows[0][ "AutoPfed "].ToString();
你改成
if(dt.Rows[0][ "AutoPfed "].ToString()==null||dt.Rows[0][ "AutoPfed "].ToString();
==string.empty)
this.par_jayname.SelectedIndex = 0;
------解决方案--------------------this.par_jayname.Items.FindByText(dt.Rows[0][ "AutoPfed "].ToString()).Selected = true
都跟你说了用这个了,你怎么就不明白呢???