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

[Solved] Save RadGrid checkbox selections by clicking a button

1 Answer 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 24 Jun 2008, 05:52 PM
I am having a problem with getting the items I have selected on the grid to write to the database when I click the add button on my form. I have posted a snippet of my code below...right now I am getting an Invalid Cast error because the sender object is being cast as a button control and the sender object that the code calls is a Checkbox.

Protected Sub cmdAddNAICS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAddNAICS.Click

CType(CType(sender, CheckBox).Parent.Parent, GridItem).Selected = CType(sender, CheckBox).Checked

Dim pvChk As Boolean

'Dim dataItem As Telerik.WebControls.GridDataItem

Dim cCoC As New cContractorClassification

If (CType(sender, CheckBox)).Checked Then

For Each dataItem As GridDataItem In gvSelectList.MasterTableView.Items

CType(dataItem.FindControl("chkSelect"), CheckBox).Checked = True

dataItem.Selected =

True

pvChk = dataItem.Selected

'If pvChk = True Then

cCoC.CONTRACTOR_SID = Session.Item(

"ContractorSID")

cCoC.MERCHANT_XREF_SID =

CInt(dataItem.Item("MERCHANT_XREF_SID").Text)

cCoC.CONTRACTOR_CLASSIFICATION_ACTIVE =

True

'cCoC.Update()

Next

Else

For Each dataItem As GridDataItem In gvSelectList.MasterTableView.Items

CType(dataItem.FindControl("chkSelect"), CheckBox).Checked = False

dataItem.Selected =

False

Next

End If

 

End Sub

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Jun 2008, 07:28 AM
Hi Steve,

Try the following code snippet to access the selected items on clicking a button.

CS:
 protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
            { 
                if (item.Selected) 
                { 
                    string strSelectedText = item[col.UniqueName].Text.ToString(); 
                } 
            } 
        } 
    } 


Thanks
Shinu.
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or