Dropdownlist如何在ASP.net中将第一个值设置为空值 [英] Dropdownlist how to set the first value as null value in ASP.net
本文介绍了Dropdownlist如何在ASP.net中将第一个值设置为空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个下拉绑定,总是从绑定数据中选择第一个值,如何将第一个值设置为空值,任何1可以帮助我
void dropdown_bind()
{
adp = new SqlDataAdapter( sp_dropdownbind ,con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
ds = new DataSet();
adp.Fill(ds);
ddlTypeid.DataTextField = 名称;
ddlTypeid.DataSource = ds.Tables [ 0 ];
ddlTypeid.DataBind();
ddlproductid.DataTextField = ProductName;
ddlproductid.DataSource = ds.Tables [ 1 ];
ddlproductid.DataBind();
}
解决方案
< ; asp:dropdownlist id = DropDownList2 runat = server appenddatabounditems = true xmlns:asp = #unknown > ;
< asp:listitem selected = True text = value = < span class =code-string> > < / asp:listitem >
< / asp:下拉列表 >
I had a dropdown bind which always selects the first value from the bound data, how to set the first value as "null value" can any 1 helps me
void dropdown_bind()
{
adp = new SqlDataAdapter("sp_dropdownbind", con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
ds = new DataSet();
adp.Fill(ds);
ddlTypeid.DataTextField = "Name";
ddlTypeid.DataSource = ds.Tables[0];
ddlTypeid.DataBind();
ddlproductid.DataTextField = "ProductName";
ddlproductid.DataSource = ds.Tables[1];
ddlproductid.DataBind();
}
解决方案
<asp:dropdownlist id="DropDownList2" runat="server" appenddatabounditems="true" xmlns:asp="#unknown"> <asp:listitem selected="True" text="" value=""></asp:listitem> </asp:dropdownlist>
这篇关于Dropdownlist如何在ASP.net中将第一个值设置为空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文