如何在下拉列表中获取数据 [英] how to fetch data in dropdown list

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

问题描述

我在表中有国家,我想在下拉列表中绑定国家但是默认选择的国家是表格中的用户国家...例子假设当我注册那个时候我被选中了我的国家是印度,当我然后在该下拉列表中登录所有国家/地区从数据库中获取但默认选择的国家/地区是''india''...我该怎么办?

请帮助我。

i have country in table and i want to bind country in dropdown but by default selected country is which is that user country in table...example suppose when i register that that time i was selected my country is india and when i login then in that dropdown all country fetch from database but by default selected country is ''india''...so how can i do????
plz help me.

推荐答案

当你的问题既是段落又是一句话时,你理解的几率很低。



我你觉得你说你想要你的下拉列表预选当前价值?这很简单。下拉列表具有选定的值属性。您可以在ASPX或后面的代码中设置它。
When your question is both a paragraph and one sentence, the odds of you making sense, are low.

I think you''re saying you want your drop down list to preselect the current value ? That''s easy. The drop list has a selected value property. You can set it in your ASPX, or in your code behind.


1。使用DataTextField =CountryName和DataValueField =CountryId绑定您的contry下拉列表

2.获取用户数据

3.一旦你获取所选用户的数据然后在你的代码后面写下面的行

ddlContry.Items.FindbyValue(usercontryid).Selected = true;
1. Bind your contry dropdown list with DataTextField = "CountryName" and DataValueField = "CountryId"
2. Fetch the user data
3. Once u fetch the data of selected user then write following line in your code behind file
ddlContry.Items.FindbyValue(usercontryid).Selected = true;


如果我没错,你想要选中用户的国家(他在注册时自己选择了什么)。

你要做的很简单。从您的表中获取数据并使用来自数据库的值分配您的国家/地区下拉列表的值。



for ex



If I am not wrong, You want the selected country of the User (What ever he had selected while registering himself).
What you have to do is very simple. Fetch data from your table and assign the value of your country dropdown with the value coming from database.

for ex

//write your query here
//after that Fetch data from database and fill dataset or datatable
//It's must to fill your Country Dropdown before assigning the selected value

ddlCountry.SelectedValue=dt.rows[0]["CountryID"].ToString();





谢谢



Thanks


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

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