Reputation: 397
Here is my aspx page:
<telerik:RadGrid runat="server" AutoGenerateColumns="False" ID="AutoPayRadGrid" AllowFilteringByColumn="False" AllowPaging="True" AllowSorting="False" ShowGroupPanel="False" PageSize="10"
OnNeedDataSource="AutoPay_NeedDataSource" AllowMultiRowSelection="True" >
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowMouseOver="RowMouseOver" />
</ClientSettings>
<SelectedItemStyle BackColor="gray" BorderColor="Purple" BorderStyle="Dashed" BorderWidth="1px" />
<PagerStyle Mode="NextPrevAndNumeric" PageSizeControlType="None" Position="Bottom"></PagerStyle>
<GroupingSettings GroupContinuesFormatString="" GroupContinuedFormatString=""></GroupingSettings>
<MasterTableView TableLayout="Fixed">
<Columns>
<telerik:GridClientSelectColumn UniqueName="CheckboxColumn"/>
<telerik:GridBoundColumn HeaderText="CustomeID" DataField="customerid" UniqueName="customerid"/>
<telerik:GridBoundColumn HeaderText="Country" DataField="maincountry" UniqueName="maincountry"/>
<telerik:GridNumericColumn HeaderText="Amount" DataField="Amount" UniqueName="Amount"/>
</Columns>
</MasterTableView>
<ClientSettings AllowDragToGroup="true"></ClientSettings>
</telerik:RadGrid>
<telerik:RadToolTip ID="RadToolTip1" runat="server" ShowEvent="FromCode" AutoCloseDelay="0"/>
<br />
<asp:Button runat="server" ID="btnvendorbills" Text="Generate Vendor Bills" OnClick="btnvendorbills_Click" />
and here is my code behind:
protected void btnvendorbills_Click(object sender, EventArgs e)
{
foreach (GridItem item in AutoPayRadGrid.MasterTableView.Items)
{
CheckBox chk = (CheckBox)item["CheckboxColumn"].Controls[0];
if (chk.Checked)
{
//code
}
}
}
But it gives me this error on compilation:
Cannot apply indexing with [] to an expression of type 'Telerik.Web.UI.GridItem'
on this line
CheckBox chk = (CheckBox)item["CheckboxColumn"].Controls[0];
Even if I try to access cell value like:
string country = item["maincountry"].Text;
It throws the same error.
Upvotes: 0
Views: 1962
Reputation: 397
foreach (GridDataItem in AutoPayRadGrid.MasterTableView.Items)
{
CheckBox chk = (CheckBox)item["CheckboxColumn"].Controls[0];
if (chk.Checked)
{
//code
}
}
Instead of GridItem it should be GridDataItem.
Upvotes: 1