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

[Solved] Access GridCheckBoxColumn

1 Answer 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 24 Sep 2009, 11:04 PM
I am trying to check the value of the checkbox in a ItemTemplate in the GridTemplateColumn.  If you notice on line 3, this is what I'm attempting to accomplish.  I know it cannot be done this way, but how might I be able to do it.

if (col.UniqueName == "SelectedLineItems") 
                    { 
                        if (dataItem[col.UniqueName].Checked) 
                    { 
                        if (col.UniqueName == "colCatalogNumber") 
                    { 
 
                       if (dataItem[col.UniqueName].Text == this.txtFindColor.Text) 
                            dataItem[col.UniqueName].Text = this.txtReplaceColor.Text; 
                        { 
                            if (dataItem[col.UniqueName].Text == this.txtReplaceColor.Text) 
                                dataItem[col.UniqueName].ForeColor = System.Drawing.Color.Crimson; 
                        } 
                    }    
                        } 
                    } 


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2009, 05:29 AM
Hi chris,

You could try the following code snippet in ItemDataBound event for checking the CheckBox value and setting the column value correspondingly.

ASPX:
 
 . . . 
<telerik:GridTemplateColumn UniqueName="GridTemplateColumn1" HeaderText="Template?"
    <ItemTemplate> 
        <asp:CheckBox ID="CheckBoxID" runat="server" /> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 
 . . . 

C#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem dataItem = (GridDataItem) e.Item; 
        CheckBox chkBox = (CheckBox)dataItem.FindControl("CheckBoxID"); 
        if(chkBox.Checked) 
        { 
            // Your code 
            dataItem["colCatalogNumber"].Text = this.txtReplaceColor.Text; 
             . . .  
        } 
    } 

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