Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1510
SelectedIndex not working on ** Page_Load **
posted

Hi there !

I'm using a SQL-Based databinded datasource for a WebCombo ( do you call it WebDRopDown?? )
and I'm having trouble having a default row selected at STARTUP !?

It works fine if I put a button ( which postBacks ) but it's not working to SELECT a row in ORGINAL Page_LOAD!

Please help ! ( this works fine if I do NOT use a databinded source ... instead just created the rows in the IDE designer ... which I do NOT want to do )

I've debugged the datasource and it has 10 rows ... and they show up when I push the DropDown on the WebCombo ... so there IS data inside it. It just won't select any row by default on the Page_Load !

Example ( Inside Page_Load event ! ):

SortableCollection<LedgerTypes> _types = new SortableCollection<LedgerTypes>();
LedgerTypes newType = new LedgerTypes();
newType.Id = -1;
newType.TypeDescription = "Allar Tegundir";

_types.Add(newType);
_types.AddRange(_service.GetLedgerTypes());
_wcLedgerCategory.DataSource = _types;

_wcLedgerCategory.SelectedIndex = 0;

I've even tried RaisePostback after the last line ... but it's not working
- NOTHING is selected in the WebCombo on the initial load of the page ( although I've debugged it and it IS running the code above )

This would be my preferred way of doing this ( see the following code below ) ... but it's NOT working :-(

protected void _wcLedgerCategory_InitializeLayout(object sender, LayoutEventArgs e)
{
 try
 {
  _wcLedgerCategory.DataTextField = "TypeDescription";
  _wcLedgerCategory.DataValueField = "Id";

  e.Layout.RowSelectorsDefault = RowSelectors.No;

  _wcLedgerCategory.Width = new Unit(150);
  _wcLedgerCategory.DropDownLayout.DropdownWidth = new Unit(150);
  e.Layout.Bands[0].Columns.FromKey("Id").Hidden = true;
  e.Layout.Bands[0].Columns.FromKey("TypeDescription").Header.Caption = "";
 }
 catch (Exception) { };
}

protected void _wcLedgerCategory_DataBinding(object sender, EventArgs e)
{
 SortableCollection<LedgerTypes> _types = new SortableCollection<LedgerTypes>();
 LedgerTypes newType = new LedgerTypes();
 newType.Id = -1;
 newType.TypeDescription = "Allar Tegundir";

 _types.Add(newType);
 _types.AddRange(_service.GetLedgerTypes());
 _wcLedgerCategory.DataSource = _types;
 
 /*foreach (UltraGridRow row in _wcLedgerCategory.Rows)
 {
  if ((Int32)row.Cells.FromKey("Id").Value == -1)
   row.Selected = true;
 }*/
 
 _wcLedgerCategory.SelectedIndex = 0;
}

Please help

regards,
EE.

p.s. it also works fine if I create a button to select the entry ... ( because it PostBacks !!!! )
but that's NOT the way I want it to be:

protected void Button1_Click(object sender, EventArgs e)
{
      _wcLedgerCategory.SelectedIndex = 0; //works
}

Parents
No Data
Reply
  • 1510
    Suggested Answer
    posted

    Christ !!!!!!!! I've found out what is was ...

    I was missing the wcLedgerCategory.DataBind( );   call ...

    wasn't sure if I needed that call, but apparantly I need it

    Thanx anyway!

     

Children
No Data