Problem with a DropDownList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a DropDownList in a ASP.NET (C#) page. This control is bound to a DataTable to get the values to display
However, the SelectedItem never seems to change

For example, if I change manually the item selected in the DropDownList, then click a SubmitButton and then try to use the property this.ddlMyList.SelectedItem.Text, the value is still the value of the first item in the list. It never changes whatever I do

Please help me !!! :-

Jenny
 
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vjsharp/html/vjwlkwalkthroughusingdatagridwebcontrolt
oreadwritedatawithvisualj.asp
-----Original Message-----
Hi,

I have a DropDownList in a ASP.NET (C#) page. This
control is bound to a DataTable to get the values to
display.
However, the SelectedItem never seems to change!

For example, if I change manually the item selected in
the DropDownList, then click a SubmitButton and then try
to use the property this.ddlMyList.SelectedItem.Text, the
value is still the value of the first item in the list. It
never changes whatever I do.
 
If you're binding the datatable to the drop down list
during the Page Load Event, ensure that the binding only
occurs when Page.IsPostback is false.

-----Original Message-----
Hi,

I have a DropDownList in a ASP.NET (C#) page. This
control is bound to a DataTable to get the values to
display.
However, the SelectedItem never seems to change!

For example, if I change manually the item selected in
the DropDownList, then click a SubmitButton and then try
to use the property this.ddlMyList.SelectedItem.Text, the
value is still the value of the first item in the list. It
never changes whatever I do.
 
Duh! Yeah sorry that was a No Brainer!

I have this new problem: I'm trying to put some LinkButton inside a Datalist. But I can't add an event handler
for the button. If I double click on the LinkButton, I get forwarded to the method : dtlMyDataList_SelectedIndexChanged,
but that method is not fired when I click on one of the buttons at runtime.

How do I go about this? Or is it a bad idea to put a Link Button in a DataList in the first place?

thanks,

Jenny
 
Hi Jenny,

The DataList control also supports the ItemCommand event
that is raised when a user clicks a button that doesn't
have a predefined command such as edit or delete. You can
use this event for custom functionality by setting a
button's CommandName property to a value you need and then
testing for it in the ItemCommand event handler.
For example:
// C#
private void DataList1_ItemCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "AddToCart")
{
// Add code here to add the item to the shopping
cart.
// Use the value of e.Item.ItemIndex to find the
data row
// in the data source.
}
}

Bin Song, MCP
-----Original Message-----
Duh! Yeah sorry that was a No Brainer!

I have this new problem: I'm trying to put some
LinkButton inside a Datalist. But I can't add an event
handler
for the button. If I double click on the LinkButton, I
get forwarded to the method :
dtlMyDataList_SelectedIndexChanged,
but that method is not fired when I click on one of the buttons at runtime.

How do I go about this? Or is it a bad idea to put a Link
Button in a DataList in the first place?
 
Back
Top