Showing posts with label names. Show all posts
Showing posts with label names. Show all posts

Saturday, March 24, 2012

Populate Dropdown with File Names

I'm working with an ASP.Net web page that's using C#. I'm trying to
populate a Dropdown with the File Names that reside in an image folder
that's in the same project. So far all I've been able to find is the
below code...and even then that's not quite what I'm after.

DirectoryInfo di = new DirectoryInfo(@dotnet.itags.org."~/Images/Entry/");
FileInfo[] fis = di.GetFiles();
DropDownList5.DataSource = fis;
DropDownList5.DataTextField = "Name";
DropDownList5.DataValueField = "Name";
DropDownList5.DataBind();

Any help in trying to get this resolved quickly would be appreciated.

ThanksOne thing I neglected to say...the Dropdown will also reside in the
EditItemTemplate of a Formview. Is there a way to bind that control if
it's there?

Thanks Again

Dave wrote:

Quote:

Originally Posted by

I'm working with an ASP.Net web page that's using C#. I'm trying to
populate a Dropdown with the File Names that reside in an image folder
that's in the same project. So far all I've been able to find is the
below code...and even then that's not quite what I'm after.
>
DirectoryInfo di = new DirectoryInfo(@."~/Images/Entry/");
FileInfo[] fis = di.GetFiles();
DropDownList5.DataSource = fis;
DropDownList5.DataTextField = "Name";
DropDownList5.DataValueField = "Name";
DropDownList5.DataBind();
>
Any help in trying to get this resolved quickly would be appreciated.
>
Thanks

Wednesday, March 21, 2012

populated a dropdown with data in the rows, but populating a dropdown with names of the co

within my pageload i have
SqlConnection rate;
SqlCommand Selct;
SqlDataReader dbresults;
rate = new SqlConnection( @dotnet.itags.org."xoxo");
rate.Open();
Selct = new SqlCommand( "Select UserID From dbo.Users", rate );
dbresults = Selct.ExecuteReader();
DropDownList1.DataSource = dbresults;
DropDownList1.DataTextField = "UserID*";
DropDownList1.DataBind();
dbresults.Close();
rate.Close();try out

...
myda = New SqlClient.SqlDataAdapter("Select * from <tablename>" , myconnection)
ds = New DataSet()
myda.Fill(ds, "TableName")
Dim dc As DataColumn
For Each dc In ds.Tables(0).Columns
ddl.Items.Add(dc.ColumnName)
Next
.....

HTH
ok heres another one ive been trying to figure out , how do a populate a drop down list with each table name in a database

populating a drop down box with ms access information

what is the best way to populate a drop down box with a list of names in a database? i'm using webmatrix/asp.net and the names are in a field called "name" .

dim ConnString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDBPath;"
dim conn As System.Data.OleDb.OleDbConnection(ConnString)
dim cmd As New OleDb.OleDbCommand()
dim dr as OleDb.OleDbDataReader
cmd.connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, name from mytable"
try
conn.open
dr = cmd.executereader() 'assuming dr is your datareader
myDropDownList.datasource = dr
myDropDownList.DataTextField = "name"
myDropDownList.DataValueField = "id" 'example of assinging a value field too
myDropDownList.Databind()
finally
conn.close
end try

This is an example using a datareader for quick access and ideal for dropdownlists. You will see examples using datasets too but this just happens to be my preference from a performance point of view.

Friday, March 16, 2012

Populating array with color values

Hi,
I'm trying to populate an array with color names. I keep getting an error.
Here is the line that fails:

Dim Colors As String() = Enum.GetValues(enumColor.GetType())Hi Roger,

You should be able to get all of the colors (including system colors) like
this:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
End If
End Sub 'Page_Load

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:DropDownList id="DropDownList1" runat="server"
AutoPostBack="True"></asp:DropDownList></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form
Ken
MVP [ASP.NET]

"Roger" <TheFlash@.Superhero.com> wrote in message
news:uguKrq64DHA.2412@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I'm trying to populate an array with color names. I keep getting an
> error.
> Here is the line that fails:
> Dim Colors As String() = Enum.GetValues(enumColor.GetType())
That worked thanks!

"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:%236cfSE74DHA.1804@.TK2MSFTNGP12.phx.gbl...
> Hi Roger,
> You should be able to get all of the colors (including system colors) like
> this:
> Private Sub Page_Load _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) _
> Handles MyBase.Load
> If Not IsPostBack Then
> Dim strSelectedColor As String
> Dim enumColor As New KnownColor
> Dim Colors As Array = _
> [Enum].GetValues(enumColor.GetType())
> DropDownList1.DataSource = Colors
> DropDownList1.DataBind()
> strSelectedColor = DropDownList1.Items(0).Text
> End If
> End Sub 'Page_Load
> Private Sub DropDownList1_SelectedIndexChanged _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArgs) _
> Handles DropDownList1.SelectedIndexChanged
> Label1.Text = DropDownList1.SelectedItem.Text
> End Sub
>
> <form id="Form1" method="post" runat="server">
> <P>
> <asp:DropDownList id="DropDownList1" runat="server"
> AutoPostBack="True"></asp:DropDownList></P>
> <P>
> <asp:Label id="Label1" runat="server"></asp:Label></P>
> </form>
> Ken
> MVP [ASP.NET]
>
> "Roger" <TheFlash@.Superhero.com> wrote in message
> news:uguKrq64DHA.2412@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> > I'm trying to populate an array with color names. I keep getting an
> > error.
> > Here is the line that fails:
> > Dim Colors As String() = Enum.GetValues(enumColor.GetType())