|
You need to do a databinding.
If you have your data in the datatable as I first described, you would do as follows.
Supposing DataTable myTable = new DataTable(); is your table where the values are stored and DropDownList ddlFoo; is your drop down list, you would bind like this:
ddlFoo.DataSource = myTable;
ddlFoo.DataTextField = "ColumnNameForText";
ddlFoo.DataValueField = "ColumnNameForValue";
ddlFoo.DataBind();
Remember that you can only bind 2 columns of the table, one column should contain the text to be displayed in the DDL and one column should contain the corresponding value for each entry.
If you are using the ArrayList as I described ArrayList myList = new ArrayList(); you need to make sure that the object that you added in the array has 2 fields where you would place the text and the value fields. I use System.Web.UI.WebControls.ListItem because this class has 2 properties Text and Value . You would then make the binding in the same way you would do for the data table:
ddlFoo.DataSource = myList;
ddlFoo.DataTextField = "Text";
ddlFoo.DataValueField = "Value";
ddlFoo.DataBind();
Here we put Text and Value because these are the names of the properties of the ListItem class, but if you used another class with other fields, you would put their name here.
Hope this helps.
Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
You can use executereader, read all the values and store them in array but in my opinion arraylist would be better as you don't know how many values you'll need to store. But why do you need it? You can store values in datatable and then access them very easily.
|
|
|
|
|
Could you please give me a sample code(using my example above) to do the same as u mentioned.......
|
|
|
|
|
http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp
|
|
|
|
|
oops, I just noticed that you wanted the results in an Array. Well instead of a data table, you can use an ArrayList and add the elements as you read them from the data reader.
Talal
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Hello friends,
Can we set the no of rows in listview.
Regards,
rahul saini
|
|
|
|
|
Hi!
The number of rows simply is equal to the number of ListViewItems that have been added to the LV.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
In this community a post written in SMSscript is not appreciated and most likely will not get an answer concerning the problem. I suggest to write in plain English so that anyone can understand and reply to help you.
I am fighting against the Universe...
Reference-Rick Cook
|
|
|
|
|
Hello friend,
Can we set the no of rows in listview.
Regards,
rahul saini
|
|
|
|
|
Hi Friends,
I try to capture whole web page opened with internet explorer as a image. I saw
the following project (http://www.codeproject.com/cs/media/IECapture.asp) But there are some problems with it.
Does any body has has done similar things.
Thanks In advance
Dinesh
|
|
|
|
|
Dinesh N Samarathunga wrote: there are some problems with it.
Maybe. you can tell us what problems you are having. maybe. we can help you..
Dinesh N Samarathunga wrote: Does any body has has done similar things.
I found one here. "Web Capture[^]"
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Thanks Michael,
I saw your link. It works fine. But it also done with a web controller. Actually I need to capture the image of current (top IE window) IE Instance.
Thanks
Dinesh
|
|
|
|
|
Dinesh, I have used the same code from code project only and it’s working just fine for me...
So please specify where exactly u r facing problem...
~Anuj~
|
|
|
|
|
Hi Anuj,
Anuj which version of IE are you using ? I am using IE 7. Can you capture a web page like gmail inbox. and http://www.php.net ?
Thanks
Dinesh
|
|
|
|
|
Hi,
I need to receive raw Kerberos token to access Exchange 2007 by IMAP. To archive this I did the following:
<br />
KerberosToken token= new KerberosToken ("imap/<EXCHANGE_HOST_SERVER_NAME>@<DOMAIN_NAME>");<br />
byte[] rawToken = token.RawData;<br />
But there is no access to Exchange server using this token. What is wrong?
|
|
|
|
|
Sorry if this is a dumb question but I am pretty new to .net c#. I want to use a button click to send a person from tabpageA to tabpageB with the focus/cursor in txtfieldA could someone please point me in the right direction on how to do this. Thanks.
Brad
|
|
|
|
|
Sorry guys I figured it out with the tabcontrol.selectedindex = 2 and txtfield.focus() entries on click of button. Knew it was something simple.
|
|
|
|
|
Hello,
Berdril wrote: to send a person from tabpageA to tabpageB
The Instance of your TabControl, where your TabPages are placed, provides the properties:
SelectedTab
SelectedIndex
If you know the instance of TabPage where you want to jump use:
yourTabControl.SelectedTab = yourTabPagetogo;
The TextBox (which is derived from Control) provides a method:
Focus
yourTextBoxToSetFocues.Focuse();
Oooops, too slow!
All the best,
Martin
|
|
|
|
|
hi there,
i m trying to get selectednode text from treeview but it always show previous selectednode (for example : if "abc" is already selected when forms load and now i select "efg" node then C# shows the selectednode "abc" and when i select another node then it shows "efg" node)
i tried it in click, mouseclick, nodemouseclick events of treeview
is this C# bug or i m doing mistake....?
Becoming Programmer...
|
|
|
|
|
It's better if you write in "AfterSelect" event.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
oh i got it thanks
Becoming Programmer...
|
|
|
|
|
Help me please !
How can I monitor an application if it start or not using C# 2.0.
Ex : I want to write an app that monitor another app if it start or not. When it start another will start automatically after 5 minutes.
Thanks a lot !
|
|
|
|
|
chuongkl77 wrote: How can I monitor an application if it start or not using C# 2.0.
Try this code.
<br />
Process[] processes=Process.GetProcessesByName("appName");
if (processes.Length > 1){<br />
Console.WriteLine("Oh my god!! it started running... So, I should start too..");<br />
return;<br />
}<br />
else{<br />
Console.WriteLine("I will sleep as long as that one is sleeping");<br />
}<br />
Note: Checking processes should be done in Window Service.
Hope it helps.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Michael Sync wrote: Console.WriteLine("Oh my god!! it started running...
|
|
|
|
|
Hello,
Michael Sync wrote: Oh my god!! it started running
I also like this one!
But, you should allways dispose your process instances!!!
All the best,
Martin
|
|
|
|