Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populating a ddl after adding a record
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00925951
Message ID:
00927944
Views:
22
Cathi;

Thank you very much. It is good to have you back on the UT.

Tom


>Hi Thomas,
>
>If you want to set the displayed DDL index, then you need to figure out which one you want. This usually means looping through the DDL items and comparing the value to some other source. Then you assign the index to be shown to the SelectedIndex property of the DDL. Here is some sample code:
>
>
>// Get the index of the row that should be preselected
>for (Index=0;Index<this.cboClients.Items.Count;Index++)
>{
>   // Check if ddl contents matches a field from a table stored in a Data Reader
>   if ((string)dr["clientno"] == this.ddlClients.Items[Index].Value)
>   {
>	break;
>   }
>}
>
>if (Index<this.ddlClients.Items.Count)
>{
>   this.ddlClients.SelectedIndex = Index;
>}
>
>
>>ASP.NET
>>
>>I am using a Drop Down List and need assistance to do the following:
>>
>>After adding a record have the Drop Down List point to that record.
>>
>>Here is how I repopulate the ddl after adding a record.
>>
>>
>>Sub GetUserUpdate()
>>        ' Update and fill ddlUsers after new User is Added...
>>        Dim SqlSelectCommand1 As New System.Data.SqlClient.SqlCommand()
>>        SqlSelectCommand1.CommandText = "SELECT UserID FROM UserInfo ORDER BY UserID"
>>        SqlSelectCommand1.Connection = SqlConnection1
>>
>>        Dim cmdUserID
>>        cmdUserID = SqlSelectCommand1.ExecuteReader()
>>
>>        ddlUsersID.DataSource = cmdUserID
>>        ddlUsersID.DataTextField = "UserID"
>>
>>        ddlUsersID.DataBind()
>>        SqlConnection1.Close()
>>
>>End Sub
>>
>>
>>After adding a record the ddl goes to BOF and displays the first record in the dataset.
>>
>>Suggestions using VB.NET or C # will be appreciated.
>>
>>Thank you.
>>
>>Tom
Previous
Reply
Map
View

Click here to load this message in the networking platform