Binding Database Table's column

4 posts, 0 answers
  1. Himanshu Thakur
    Himanshu Thakur avatar
    11 posts
    Member since:
    Nov 2009

    Posted 29 Nov 2009 Link to this post

    Hi,

    I am trying to bind the database table's column with the checkbox in front of each Items fetched into ListView from the DB Table.

    upto this I'm able to do as I want to. But the problem arises when i need to fetch the selected value of Item (with checkbox checked for that perticulat item).

    The value of the checked Item would be fetch on Button_Click event.

    Apparently, I am not able to get the selected value into any of the label or text box.( as checkbox implementation has been provided in demos for ListView, Probably because items have been hard coded in the demo and the Items which I am trying to populate will be dynamic at the period of time.)

    Any suggestions?

    Cheers!
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 30 Nov 2009 Link to this post

    Hi Himanshu,

    I'm afraid that I'm not totaly sure what exactly is the scenario described. However I have attached a simple demo page which demonstrates how to use checkboxes to toggle the RadListView selection  and to retrieve the items' value on button click.

    Greetings,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Himanshu Thakur
    Himanshu Thakur avatar
    11 posts
    Member since:
    Nov 2009

    Posted 30 Nov 2009 Link to this post

    Hi Rosen,

    Thank you for the reply and the code.

    Just to explain bit more and again about the scenario.

    I have a view which has all the data I need to display(partial or full) on a perticular page. Now one of the column is "CITY" and I fetch the distinct CITIES from the view, which would be displayed in ListBox(preferred)/(ListView) with a checkbox in front of each item(i.e. CITY fetched from view).

    On selection of 1 or multiple checkboxes(which would represnt CITY) I could be able to fetch the value of SelectedItem, so that I can use those selections in my LINQ query.

    Hope it makes bit of sense now :)

    Regards
  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 01 Dec 2009 Link to this post

    Hi Himanshu,

    You can use CheckBox's CheckedChanged event to get the value of the item to which the checkbox belongs similar to the following:

    protected void chkSelect_CheckedChanged(object sender, EventArgs e)
     {
         CheckBox checkBox = (CheckBox)sender;
         RadListViewDataItem dataItem = (RadListViewDataItem)checkBox.NamingContainer;

         var itemValue = (string)dataItem.GetDataKeyValue("col1");

         dataItem.Selected = checkBox.Checked;
         dataItem.OwnerListView.Rebind();
     }

    For how to extract SelectedItems' values on a external button click you may refer to previously attached demo page.

    Best wishes,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top