hi!
(language :c#)
i am in big trouble..
i have a combobox in which i am getting through database.
now after binding it i need to get the first value of it i.e., the value of index=0 but i am not getting it.
my code goes like this::
SqlConnection con1 = new SqlConnection("data source='.\\sqlexpress';database=gimage;integrated security=true;");
SqlCommand com1 = new SqlCommand("select * from cropSize");
SqlDataAdapter adp1 = new SqlDataAdapter();
DataSet ds1 = new DataSet();
com1.Connection = con1;
adp1.SelectCommand = com1;
adp1.Fill(ds1);
cmbSelectedCropBoxSize.DataSource = ds1.Tables[0];
cmbSelectedCropBoxSize.SelectedIndex = 0;
now after this if i do
string txt;
txt = cmbSelectedCropBoxSize.SelectedItem.ToString();
i am getting System.Data.DataRowView
if i do the following i am getting nothing.
txt = cmbSelectedCropBoxSize.SelectedText.ToString();
what should i do now..please help me out!!
nandini |
| NandiniP Wednesday, September 16, 2009 8:04 AM |
use
txt =cmbSelectedCropBoxSize.Items[0].ToString()
- Marked As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:12 AM
- Proposed As Answer byBharath kumar Y.S Wednesday, September 16, 2009 8:47 AM
-
|
| Bharath kumar Y.S Wednesday, September 16, 2009 8:46 AM |
just a note : add this condition also
if(cmbSelectedCropBoxSize.Items.Count > 0) txt = cmbSelectedCropBoxSize.Items[0].ToString(); Paras- Proposed As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:11 AM
- Marked As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:12 AM
-
|
| paras kumar Wednesday, September 16, 2009 9:29 AM |
use
txt =cmbSelectedCropBoxSize.Items[0].ToString()
- Marked As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:12 AM
- Proposed As Answer byBharath kumar Y.S Wednesday, September 16, 2009 8:47 AM
-
|
| Bharath kumar Y.S Wednesday, September 16, 2009 8:46 AM |
just a note : add this condition also
if(cmbSelectedCropBoxSize.Items.Count > 0) txt = cmbSelectedCropBoxSize.Items[0].ToString(); Paras- Proposed As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:11 AM
- Marked As Answer byAland LiMSFT, ModeratorThursday, September 17, 2009 10:12 AM
-
|
| paras kumar Wednesday, September 16, 2009 9:29 AM |
hi!
thanks for ur reply but
this way i am getting -1
nandini |
| NandiniP Wednesday, September 16, 2009 11:36 AM |
is the problem solved ..if notcan you give discriptionof the problem what that -1 is.. |
| Bharath kumar Y.S Wednesday, September 16, 2009 11:42 AM |
Are you saying that cmbSelectedCropBoxSize.Items[0].ToString(); is returning -1?? Paras |
| paras kumar Wednesday, September 16, 2009 1:07 PM |