473,382 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

problem in binding values with dropdownlist

ndhamecha
i have a problem in binding values with dropdownlist.i have one dropdownlist name,dropdowndiagnosticcategory..i have made one function bind_category() for binding the category values.The code for binding the values with dropdownlist is as under,here

Expand|Select|Wrap|Line Numbers
  1.  private void bind_category()
  2.     {
  3.  
  4.         string s = "Data Source=LAB1-40;Initial Catalog=MNSDaignosticCenter;Integrated Security=True";
  5.         SqlConnection con = new SqlConnection(s);
  6.         con.Open();
  7.  
  8.         SqlCommand cmd = new SqlCommand("select DiagnosisCategoryId,DiagnosisCategoryName from TblDiagnosisCategory");
  9.         SqlDataAdapter sda = new SqlDataAdapter(cmd);
  10.         DataSet ds = new DataSet();
  11.         sda.Fill(ds);
  12.  
  13.         if (ds != null && ds.Tables[0].Rows.Count > 0)
  14.         {
  15.             DropDownDiagnosticCat.DataSource = ds;
  16.             DropDownDiagnosticCat.DataTextField = "DiagnosisCategoryName";
  17.             DropDownDiagnosticCat.DataValueField = "DiagnosisCategoryId";
  18.             DropDownDiagnosticCat.DataBind();
  19.         }
  20.         DropDownDiagnosticCat.Items.Insert(0, "-Select category");
  21.         sda.Dispose();
  22.         con.Close();
  23.  
  24.     }
  25.  
  26.  protected void DropDownDiagnosticCat_SelectedIndexChanged(object sender, EventArgs e)
  27.     {
  28.         bind_category();
  29.     }
  30.  
  31.  

would you please give me suggestion to display data in this gridview.this is not giving any error.but even not given values to select from this gridview.

thanking you.
ndhamecha
Apr 28 '10 #1
2 2026
Frinavale
9,735 Expert Mod 8TB
I'm sorry that I don't understand your question but...
What does the GridView have to do with the DropDownList?
Apr 28 '10 #2
Frinavale
9,735 Expert Mod 8TB
ndhamecha:
hello.
i found my mistake..yes.but before that.i want to tell you what i am doing right now.
i have taken one dropdown list,which contains the list of categories of diagnosis.&made one function for binding that dropdownlist with sqlserver 2005 using connection string.and that function,i am calling on dropdownlist_selected_index_changed event..getting?
but i found my mistake was that.when i wrote my select query for getting values of diagnosis category from database i forgot to pass object of connection string also.
so..the it should be like this:-
SqlCommand cmd = new SqlCommand("select DiagnosisCategoryId,DiagnosisCategoryName from TblDiagnosisCategory",con);
I'm happy that you were able to solve your problem (even though I'm still not sure what the GridView had to do with anything).


ndhamecha:
yes..1 more thing.i am not rude.but using this site first time.even i don't know,how to present ourselves in front of great developers.so i am really extremely sorry if i am hurting u all from my language.but believe me,my intention is not to hurt anyone.

thanks for your reply :)

ndhamech
You haven't been rude yet :)
The one thing you should be aware of is that this forum likes to keep solutions to problems public so that other people with the same problem can find an answer in the discussions that we have in your thread. So, we do not help solve problems privately using PMs. I know it's a bit confusing because of the automated system that PMs you to let you know when someone has replied to your question...but please reply in thread instead of in PMs.

I've posted your PM here so that people can see what you said :)

-Frinny
Apr 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christian | last post by:
Hi, I have a datagrid on an ASP.NET page, which has a custom columntemplate. In this columntemplate I would like to have a DropDownList, which is shown, when the user edits the record....
4
by: Jenny C. | last post by:
Hi I have a DropDownList in a ASP.NET (C#) page. This control is bound to a DataTable to get the values to display However, the SelectedItem never seems to change For example, if I change...
1
by: Harry | last post by:
Hi, Just seeing if anyone can help me with a problem I am having with drop down lists. - I have a asp:dropdownlist that gets its values from a database. - The user then selects a value then...
0
by: RAMADU | last post by:
Hi There is a ListItemCollection containing ListItems (of course), each of whose Value and Text properties have been set. The Value and Text's values are different i.e. ListItem.Text = "Name0"...
2
by: RAMADU | last post by:
Hi There is a ListItemCollection containing ListItems (of course), each of whose Value and Text properties have been set. The Value and Text's values are different i.e. ListItem.Text = "Name0"...
1
by: Mike Bridge | last post by:
I'm getting a nonsensical error when binding a DataTable with one row to a DropDownList. The DataTable's row contains the fields "id" (INT), "description" (VARCHAR) and with a couple other...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
2
by: =?Utf-8?B?VmljdG9yaW91czE=?= | last post by:
When the editcommand is execured for my datagrid the dropdown list appears for the bound item status. However, the item selected by default does not match the unedited data. How do I make the...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.