RadListBox checked attribute

7 posts, 1 answers
  1. Lighthouse Developer
    Lighthouse Developer avatar
    34 posts
    Member since:
    Feb 2010

    Posted 07 May 2010 Link to this post

    Hi. Here's my problem:

    I'm trying to set some items in a ListBox to be checked after the ListBox is databound. My problem is that even though the loop is executed and Visual Studio reports each item I want as checked = true, it doesn't appear to be so. Any suggestions?

                
                rlbRoles.DataBind(); 
                stmt = 
                    @"Select auth_Roles.Name as Name, auth_Roles.NameEL as NameEL from auth_Roles INNER JOIN auth_UserRoles on auth_UserRoles.RoleId = auth_Roles.RoleId INNER JOIN auth_Users on auth_UserRoles.UserId = auth_Users.UserId 
                        WHERE auth_Users.UserId = @UserId"
     
                dt = DbSql.ExecuteDataTable(stmt, 
                                            new List<SqlParameter>(new[] 
                                                                       { 
                                                                           new SqlParameter("@UserId"
                                                                                            DataBinder.Eval(sender, 
                                                                                                            "DataItem.ID")) 
                                                                       } 
                                                ) 
                    ); 
     
                int i = 0; 
                foreach (DataRow r in dt.Rows) 
                { 
                    rlbRoles.FindItemByValue(dt.Rows[i]["Name"].ToString()).Checked = true
                    i++; 
                } 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2010 Link to this post

    Hi,

    Your code works good when I tried on my end. Could you try the code in DataBound event of RadListBox and see whether it is working fine?

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lighthouse Developer
    Lighthouse Developer avatar
    34 posts
    Member since:
    Feb 2010

    Posted 07 May 2010 Link to this post

    My problem is getting 
    DataBinder.Eval(sender,
    "DataItem.ID")

    in DataBound...
  5. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 10 May 2010 Link to this post

    Hello Lighthouse Developer,

    You should e.Item instead of sender as first parameter for DataBinder.Eval. Example code:

    protected void RadListBox1_ItemDataBound(object sender, RadListBoxItemEventArgs e)
        {
            string id = (string)DataBinder.Eval(e.Item, "DataItem['ID']");
        }


    Best wishes,
    Genady Sergeev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Lighthouse Developer
    Lighthouse Developer avatar
    34 posts
    Member since:
    Feb 2010

    Posted 10 May 2010 Link to this post

    I still can't get it because ID comes from the editform's datasource (Does that make sense?)  It's something like

    <asp:TextBox id="txtPassQ" Text='<%# DataBinder.Eval( Container, "DataItem.PasswordQuestion") %>' runat="server" tabIndex=8>

    on the aspx file. Any way to get that value? (DataItem.ID). It's not in the ListBox's DataSource...
  7. Answer
    Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 14 May 2010 Link to this post

    Hello Lighthouse Developer,

    You can do the following:

    1) Into your codebehing page create property ID of type int.
    2) Hook on the ItemDataBound event of RadGrid and use the following code:

    void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
      {
          if (e.Item is GridEditableItem && e.Item.IsInEditMode)
          {
              ID = (int)DataBinder.Eval(e.Item.DataItem, "ID");
          }
      }

    Then in the DataBound event you can use freely use it.

    Greetings,
    Genady Sergeev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Lighthouse Developer
    Lighthouse Developer avatar
    34 posts
    Member since:
    Feb 2010

    Posted 17 May 2010 Link to this post

    But I don't need to use it in the RadGrid. I need to use it in the code behind of the control that I use as an edit form.

    EDIT: It's ok. I was able to solve it in a similar way. Thanks for pointing me in the right direction.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017