DropDownList

E

Eugene Anthony

Connection code:

SqlConnection cnn = new
SqlConnection(ConfigurationManager.ConnectionStrings["myConnection"].Con
nectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "SELECT * FROM Authentication WHERE
AuthenticationID=1";
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Authentication");

ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();


My dropdownlist control:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Enabled</asp:ListItem>
<asp:ListItem>Disabled</asp:ListItem>
</asp:DropDownList>


Lets say ds.Tables[0].Rows[0].ItemArray.GetValue(5).ToString(); returns
"Disabled", how do I display it on my dropdownlist?


Eugene Anthony
 
R

Rob

Eugene said:
Lets say ds.Tables[0].Rows[0].ItemArray.GetValue(5).ToString(); returns
"Disabled", how do I display it on my dropdownlist?

' declare variables
Dim listItem As ListItem

' instantiate
listItem = New listItem

' populate
listItem.Text = ' your text to display here
listItem.Value = ' your value here

' add listItem to DropDownList1
DropDownList1.Items.Add(listItem)

' housekeeping
listItem = Nothing

HTH

Regards

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

dropdownlist 4
System.Data.DataRow error 1
session 1
Prolem with parameter! 3
DropDownList 1
xmldatareader? 3
How to bind a label to a dataset with C# 4
problem with dropdownlist inside of datagrid 2

Top