l.value =(0)和li.value = dr.item(0)和li.text = dr.item(1)进行错误请检查并解决先生 [英] l.value=(0) and li.value=dr.item(0) and li.text=dr.item(1) conduct the error please check and solve sir please
本文介绍了l.value =(0)和li.value = dr.item(0)和li.text = dr.item(1)进行错误请检查并解决先生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public DataSet fill_combo(DropDownList ddl, string 字段,< span class =code-keyword> string tbl, string condition)
{
SqlDataReader dr = 默认跨度>(SqlDataReader的);
string [] a = null ;
ddl.Items.Clear();
ListItem l = new ListItem();
l.Text = 选择;
l.Value =( 0 );
ddl.Items.Add(l);
dr = viewrecord_dr(field,tbl,condition);
if (field.Contains( , ))
{
a = field.Split(' ,'跨度>);
while (dr.Read())
{
ListItem li = new ListItem();
li.Value = dr.Item( 0 );
li.Text = dr.Item( 1 );
ddl.Items.Add(li);
}
}
其他
{
而(dr.Read())
{
ddl.Items.Add(dr.Item( 0 ));
}
}
dr.Close();
}
解决方案
dr
是SqlDataReader [ ^ ],对吗?
其项目 [ ^ ]属性已编入索引。 C#中的索引在方括号中给出,如此处li.Value = dr.Item [ 0 ];
对于另一部分,我只能猜测
l
的类型是 System.Web.UI.Controls.ListItem [ ^ ]。其价值 [ ^ ]属性类型 System.String [ ^ ],就像您设置的其他属性一样。因此你不能给它分配一个零(括号在这里什么都不做)。使用l.Value = 0;
public DataSet fill_combo(DropDownList ddl, string field, string tbl, string condition)
{
SqlDataReader dr = default(SqlDataReader);
string[] a = null;
ddl.Items.Clear();
ListItem l = new ListItem();
l.Text = "select";
l.Value = (0);
ddl.Items.Add(l);
dr = viewrecord_dr(field, tbl, condition);
if (field.Contains(","))
{
a = field.Split(',');
while (dr.Read())
{
ListItem li = new ListItem();
li.Value = dr.Item(0);
li.Text = dr.Item(1);
ddl.Items.Add(li);
}
}
else
{
while (dr.Read())
{
ddl.Items.Add(dr.Item(0));
}
}
dr.Close();
}
解决方案
dr
is an SqlDataReader[^], right?
Its Item[^] property is indexed. Indexes in C# are given in square brackets like hereli.Value = dr.Item[0];
For the other part, I can only guess that
l
is of type System.Web.UI.Controls.ListItem[^]. Its Value[^] property is of type System.String[^], just as the other property you set. Therefore you cannot assign a zero to it (the parentheses do exactly nothing here). Usel.Value = "0";instead. Or, if the zero represents a variable, use that variable's ToString[^] overload.
这篇关于l.value =(0)和li.value = dr.item(0)和li.text = dr.item(1)进行错误请检查并解决先生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文