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

[Solved] Cannot select GridClientSelectColumn from code behind

1 Answer 285 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 18 Jun 2009, 10:17 PM

 

 

I've got the following code in place to check the GridClientSelectColumn from my code behind and it indeed fires and the check boxes are checked but when the page finally renders none of the check boxes are checked. I've tried both the ItemDataBound and the ItemCreated events and neither produce a different result. The following article is were I got my code: http://www.telerik.com/community/code-library/aspnet-ajax/grid/gridclientselectcolumn-select-all-rows-with-enabled-check-boxes-only.aspx


<
telerik:RadGrid ID="StepsGrid" runat="server" AllowSorting="True" EnableAJAX="true"

 

 

 

 

 

ClientSettings-Selecting-AllowRowSelect="true" GridLines="None" Skin="Sunset"

 

 

 

 

 

HeaderStyle-Wrap="false" AutoGenerateColumns="False"

 

 

 

 

 

AllowMultiRowSelection="true" onitemdatabound="StepsGrid_ItemDataBound"

 

 

onitemcreated="StepsGrid_ItemCreated">

 

 

 

 

 

<HeaderStyle Wrap="False"></HeaderStyle>

 

 

 

 

 

<ClientSettings EnableRowHoverStyle="true" Selecting-AllowRowSelect="true">

 

 

 

 

 

<Selecting AllowRowSelect="true" />

 

 

 

 

 

</ClientSettings>

 

 

 

 

 

<ItemStyle Wrap="False" />

 

 

 

 

 

<MasterTableView CommandItemDisplay="TopAndBottom" CellSpacing="-1" DataKeyNames="StepGuid">

 

 

 

 

 

<CommandItemTemplate>

 

 

 

 

 

<asp:Button CssClass="CustomButton" runat="server" ID="AddSteps" Text="Add Steps" OnClick="AddSteps_Click" />

 

 

 

 

 

</CommandItemTemplate>

 

 

 

 

 

<RowIndicatorColumn Visible="False">

 

 

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

 

 

</RowIndicatorColumn>

 

 

 

 

 

<ExpandCollapseColumn Visible="False">

 

 

 

 

 

<HeaderStyle Width="19px"></HeaderStyle>

 

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

 

<EditItemStyle CssClass="GridEditStyle" />

 

 

 

 

 

<Columns>

 

 

 

 

 

<telerik:GridBoundColumn UniqueName="StepGuid" DataField="StepGuid" HeaderText="StepGuid"

 

 

 

 

 

Visible="false" />

 

 

 

 

 

<telerik:GridClientSelectColumn ButtonType="ImageButton" UniqueName="SelectedCheckbox" />

 

 

 

 

 

<telerik:GridBoundColumn DataField="Name" HeaderText="Name" />

 

 

 

 

 

<telerik:GridBoundColumn DataField="Command" HeaderText="Command" />

 

 

 

 

 

<telerik:GridBoundColumn DataField="ServerArguments" HeaderText="Server Arguments" />

 

 

 

 

 

<telerik:GridBoundColumn DataField="WorkingDirectory" HeaderText="Working Directory" />

 

 

 

 

 

<telerik:GridBoundColumn DataField="CreateTime" HeaderText="CreateTime" ReadOnly="true" />

 

 

 

 

 

</Columns>

 

 

 

 

 

<EditFormSettings>

 

 

 

 

 

<EditColumn UniqueName="Edit1">

 

 

 

 

 

</EditColumn>

 

 

 

 

 

</EditFormSettings>

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

 

 

 

Code behind:

protected

 

void StepsGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

 

{

 

// get the package guid for the current iteration

 

 

if (e.Item is GridDataItem)

 

{

 

DataRowView dataRow = (DataRowView)e.Item.DataItem;

 

 

GridDataItem item = (GridDataItem)e.Item;

 

 

CheckBox checkBox = (CheckBox)item["SelectedCheckbox"].Controls[0];

 

checkBox.Checked = (((

int)dataRow["Selected"]) == 1);

 

 

if (checkBox.Checked)

 

{

 

string t = "";

 

}

}

}

 

protected void StepsGrid_ItemCreated(object sender, GridItemEventArgs e)

 

{

 

// get the package guid for the current iteration

 

 

if (e.Item is GridDataItem)

 

{

 

DataRowView dataRow = (DataRowView)e.Item.DataItem;

 

 

GridDataItem item = (GridDataItem)e.Item;

 

 

CheckBox checkBox = (CheckBox)item["SelectedCheckbox"].Controls[0];

 

checkBox.Checked = (((

int)dataRow["Selected"]) == 1);

 

 

if (checkBox.Checked)

 

{

 

string t = "";

 

}

}

1 Answer, 1 is accepted

Sort by
0
Joey
Top achievements
Rank 1
answered on 19 Jun 2009, 06:29 AM
Solved it myself. Just needed this:

item.Selected =

true;

there is no need to go to this level:
CheckBox checkBox = (CheckBox)item["SelectedCheckbox"].Controls[0];

 

Tags
Grid
Asked by
Joey
Top achievements
Rank 1
Answers by
Joey
Top achievements
Rank 1
Share this question
or