Home All Groups Group Topic Archive Search About

Problem in Setting SelectedValue for DropdownList in Form

Author
30 Dec 2005 4:38 AM
Charleees
Hi all,
I have a Problem in  Setting the Dropdown selected value.

I have a Page where i get the input for the number of rows and columns
and generate a dynamic table on another page ie) table page.
If i select edit button in table page , the page is redirected to Input
page .
In the input page i have a panel where i have 6 dropdown, which
indicates the Colspan and Rowspan Cordinates and number of Rows and Col
Spaans.
The problem is when i click the edit button, i have to set the selected
value of these dropdowns to some values ie) the table properties .
If the tables row is 3 and Column is 4 , i have to set the row_ddl to 3
and also column_ddl to 4.

I assidn the selected value for these dropdowns as

ddl.selectedvalue = "value"

when i debug , i was getting the right values in the line , but thses
changes are not reflected in the Form.
I am filling the Ddl in Pageload and only if    !(page.Ispostback).

Can any one help me please..........

Thanks in advance

Author
30 Dec 2005 4:51 AM
Phillip Williams
Whatever changes to the dropdownlist that you did during the Page_Load will
be lost if the dropdownlist is databound to a datasource.  You should set the
selected value of the dropdownlist during the DataBound event.

void column_dll_DataBound(object sender, EventArgs e)
    {
        //set here the selectedvalue
        ListItem li = ((DropDownList)sender).Items.FindByValue("4");
        if (li != null)   //item was found that has the selected value
        {
            ((DropDownList)sender).ClearSelection();    //clear the old
selection first
            li.Selected = true;     //set the new selection
        }
    }
Show quoteHide quote
"Charleees" wrote:

> Hi all,
> I have a Problem in  Setting the Dropdown selected value.
>
> I have a Page where i get the input for the number of rows and columns
> and generate a dynamic table on another page ie) table page.
> If i select edit button in table page , the page is redirected to Input
> page .
> In the input page i have a panel where i have 6 dropdown, which
> indicates the Colspan and Rowspan Cordinates and number of Rows and Col
> Spaans.
> The problem is when i click the edit button, i have to set the selected
> value of these dropdowns to some values ie) the table properties .
> If the tables row is 3 and Column is 4 , i have to set the row_ddl to 3
> and also column_ddl to 4.
>
>  I assidn the selected value for these dropdowns as
>
> ddl.selectedvalue = "value"
>
> when i debug , i was getting the right values in the line , but thses
> changes are not reflected in the Form.
> I am filling the Ddl in Pageload and only if    !(page.Ispostback).
>
> Can any one help me please..........
>
> Thanks in advance
>
>
Author
30 Dec 2005 1:43 PM
Charleees
hi

i dont have to do anything like databound
i have just 10 values in my dropdown and i have to set according to the
variables values i assign

if i tell 2 then the selected value should be to 1

if i do this i could not set the value i selected

i get some defaults

what should i do

when i assign i get right values ( i checked in debug mode)

please help