asp.net中的下拉列表 [英] Dropdown list in asp.net

查看:104
本文介绍了asp.net中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有下拉列表如果我选择了所选的vaue,请不要插入数据库,它默认采用下拉列表中的第一个值。





任何人都可以帮我解决这个问题

i had dropdown list in my page if i selected the selected vaue dosen't inserting into the DB it defaultly takes the first value in the dropdown list.


can any one help me to solve this probs

推荐答案

我想你期待这个......



i think you expect this one...

<asp:dropdownlist id="ddlCountry" runat="server" cssclass="textboxStyle1"
   AppendDataBoundItems="True"  >
 <asp:listitem value="-1">-- Select --</asp:listitem>
  </asp:dropdownlist>


绑定下拉列表里面

如果(!IsPostBack)

{

//将你的下拉列表绑在这里

}
Bind the dropdownlist inside
if(!IsPostBack)
{
// Bind your Dropdownlist Here
}


<asp:dropdownlist id="ddlCountry" runat="server" >
   <asp:listitem value="-1">Your Item</asp:listitem>
     
   //add line items here
     </asp:dropdownlist>





但你必须知道你要插入哪个,价值或物品。



和在db中你必须指定该列的数据类型,无论是int(for value)还是nvarchar(对于item)





But you have to know which you are going to insert, Value or item.

and in db you have to specify the datatype for that column whether int (for value) and nvarchar (for item)

DropDownList1.SelectedItem;     //it will insert the selected text
    DropDownList2.SelectedValue

//它会插入值





如果您需要更多说明,请在此处粘贴您的代码。

//it will insert value


Still if you need more clarification paste your code here.


这篇关于asp.net中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆