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

RadGrid and Checkbox

3 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thaya
Top achievements
Rank 1
Thaya asked on 12 Jul 2010, 01:23 PM
Hi,

I have following template column i a Radgrid. (using in connection with a product order where a user can choose a number of products.)
            <Columns>
                <telerik:GridTemplateColumn>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkProduct" runat="server" />
                    </ItemTemplate>
            </Columns>

At the code behind I want to find out which products are choosen by the users (when I save product orders into database), in other words I want to know which are the checkbox's are checked at the save.

I hope someone can help me.

Thanks,
Thaya


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jul 2010, 01:39 PM
Hello Thaya,


Use the following code to retrieve the cell values of checked rows from code behind.

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write("Selected Products: ");
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items) // Loop through each items
    {
        CheckBox chkBox = (CheckBox)item.FindControl("chkProduct"); // Get the checkbox control
        if (chkBox.Checked)
        {               
            Response.Write(item["ProductName"].Text+",");
        }
    }
}



Thanks,
Princy.
0
Mike
Top achievements
Rank 1
answered on 20 May 2011, 09:47 PM
I am also having trouble with this code.  I received the following error message in IE 8

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; InfoPath.3; MS-RTC LM 8)
Timestamp: Fri, 20 May 2011 20:45:13 UTC

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'System.NullReference'.
Line: 6
Char: 62099
Code: 0
URI: http://localhost/Logistics_II3/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d3.5.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3a111e8464-2436-44db-9b34-0d84ed5253c8%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%2c+Version%3d2010.3.1317.35%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3aen-US%3ad7b88a55-4248-43ee-a9ed-d9058fd97467%3a16e4e7cd%3af7645509%3aed16cbdc%3a58366029%3a24ee1bba%3af46195d3%3a1e771326%3aaa288e2d%3ae330518b%3ac8618e41%3ae4f8f289

My code is as follows: (using VB.net)
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try


            For Each item As GridDataItem In radgvPOD.MasterTableView.Items
                ' Loop through each items
                Dim chkBox As CheckBox = DirectCast(item.FindControl("CheckboxSelectColumn"), CheckBox)
                ' Get the checkbox control
                If chkBox.Checked Then
                    Label1.Text += item("fk_Rec_ID").Text + ","
                End If
            Next
        Catch ex As Exception
            Response.Write(ex.ToString)
        End Try
    End Sub
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 May 2011, 09:14 AM
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write("Selected Products: ");
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items) // Loop through each items
    {
        CheckBox chkBox = (CheckBox)item.FindControl("chkProduct"); // Get the checkbox control
        if(chkBox  != null)
        {
            if (chkBox.Checked)
              {              
               Response.Write(item["ProductName"].Text+",");
             }
       }
      else
      {
        // check box was not found.
      }
    }
}
Hi

The code given by SHINU is perfect.
but if u get error than add one more condition for checking the checkbox was available in grid or not.


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Thaya
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or