如何在下拉列表中进行数据绑定

问题描述:

我是dotnet的新手.你能向我解释一下


我有一个下拉列表和两个文本框(名称,年龄).
如果我将从ddl中选择值,则相应的数据应出现在两个文本框中.
完整的代码是什么....

hi i am new in dotnet. can u explain me about


i have one dropdownlist and two textboxes(name,age).
if i will select the value from ddl the corresponding data should come in both textboxes.
what is the full code for this....

在下拉列表的选定更改事件上编写代码,并将其autopost属性设置为true.
write code on the selected change event of Dropdown List and make it autopost property true.


试用
http://www.aspfree .com/c/a/ASP.NET/ASPNET-Dropdown-List-Control-Eight-Ways-to-Bind-Data/ [ http://www.codersource.net/asp-net/asp-net-articles/dropdownlist-in-asp-net.aspx [ http://www.akadia.com/services/dotnet_databinding.html [
Try out
http://www.aspfree.com/c/a/ASP.NET/ASPNET-Dropdown-List-Control-Eight-Ways-to-Bind-Data/[^]
http://www.codersource.net/asp-net/asp-net-articles/dropdownlist-in-asp-net.aspx[^]
http://www.akadia.com/services/dotnet_databinding.html[^]


你好,亲爱的,

将下拉菜单的vlaue字段设置为age,将文本字段设置为name.
此时,在设计页面的下拉菜单中添加项目.
< asp:DropDownList ID ="ddlCount" runat ="server" CssClass ="ddl" Width ="92.5%">
< asp:ListItem文字=名称''值="10''> 1</asp:ListItem>
</asp:DropDownList>

如果通过数据源在CS页面中添加了项目,则使用以下代码.
ddl.DataTextField =''名称'';
ddl.DataValueField =``年龄'';

如果在不使用数据源的情况下添加了项目,则使用下面的代码
ListItem lilima =新的ListItem();
lilima.Text ="gunu";
lilima.Value ="1";
ddl.Items.Add(lilima);



在下拉列表中,selected更改事件请记住将ddl的autopostback属性设置为true,否则selectedindexchanged事件不会触发.


textBox1.text = ddl.SelectedItem.Text
textBox2.text = ddl.SelectedValue.Tostring();
Hello Dear,

set the vlaue field for the dropdown as age and the text field as the name.
At the time adding the items in the dropdown in the designing page.
<asp:DropDownList ID="ddlCount" runat="server" CssClass="ddl" Width="92.5%">
<asp:ListItem Text=''Name'' Value=''10''>1</asp:ListItem>
</asp:DropDownList>

if added items in the cs page through datasource then use below code.
ddl.DataTextField=''Name'';
ddl.DataValueField= ''Age'';

if added itmes without using datasource then use below code
ListItem lilima = new ListItem();
lilima.Text = "gunu";
lilima.Value = "1";
ddl.Items.Add(lilima);



In the dropdown selected changed event remember to make the autopostback property of ddl set to true otherwise the selectedindexchanged event won''t fire.
write

textBox1.text= ddl.SelectedItem.Text
textBox2.text= ddl.SelectedValue.Tostring();