hi all i m using asp.net 2005 and sql server 2005...i have a dropdown list in my page...i have a table called as details...all i want to do is bind the fname from details table to dropdownlistbox...but the thing is tht i want to each and every step through coding...is it possible to do so....pls let me know how to do it,,,,,,,frm whr do i strt ...
thnks in advance
johnny.g
0
Junior Poster in Training
Recommended Answers
Jump to Postprotected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlDataSource mySource = new SqlDataSource("Data Source=SERKAN\\MYSQLSERVER2005;Initial Catalog=deneme;Integrated Security=True;Pooling=False", "select * from names"); myDropDown.DataSource = mySource.Select(DataSourceSelectArguments.Empty); myDropDown.DataValueField = "PKID"; myDropDown.DataTextField = "name"; myDropDown.DataBind(); } }
Jump to PostYes you can. Follow these steps.
1).Create a query which fetches the fname from details table.
2).Call cmd.ExecuteReader with this query.
3).Now bind the dropdownlist from the datareade.For this step you can use the following code.
<dropdownlist>.DataSource = <datareader>
<dropdownlist>.DataBind()
Jump to PostWell, your sql query is fetching all columns from the table and your dropdownlist cannot be bound to such a recordset.
What you need to do is modify your sql query to fetch only fname as inselect fname from details
Jump to PostDo fill in the rest of the details
Dim li As ListItem If rd.HasRows Then Do While rd.Read li = New ListItem li.Text= rd.Item("fname") li.Value = rd.Item("srid") <dropdownlist>.Items.Add(li) Loop rd.close() End If
All 17 Replies
serkan sendur
821
Postaholic
Banned
johnny.g
commented:
as usual,,he always comes up with an answer,thnks
+1
johnny.g
0
Junior Poster in Training
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
0
Junior Poster in Training
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
0
Junior Poster in Training
bala24
5
Junior Poster
johnny.g
commented:
he is good in solving the technical terms
+1
johnny.g
0
Junior Poster in Training
jpramac
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.