This is a migrated thread and some comments may be shown as answers.

Binding Database Table's column

3 Answers 97 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Himanshu Thakur
Top achievements
Rank 1
Himanshu Thakur asked on 30 Nov 2009, 03:13 AM
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!

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 30 Nov 2009, 11:30 AM
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.
0
Himanshu Thakur
Top achievements
Rank 1
answered on 30 Nov 2009, 10:38 PM
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
0
Rosen
Telerik team
answered on 01 Dec 2009, 04:33 PM
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.
Tags
ListView
Asked by
Himanshu Thakur
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Himanshu Thakur
Top achievements
Rank 1
Share this question
or