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

GridTemplateColumn inside a Rad Grid

3 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kalpana
Top achievements
Rank 1
Kalpana asked on 14 Aug 2014, 10:22 AM
Dear Team,

I have a rad Grid, with in which I have created a  checkbox column and assing the Data to this grid. The check box is getting check or unchecked according to the Data. Perferct till here.

<telerik:GridTemplateColumn HeaderText="IsIndividual" UniqueName="IsIndividual" ReadOnly="true">
<ItemTemplate>
<asp:CheckBox ID="chkboxIsIndividual" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>

But this check box appears editable, I can uncheck/ check it in the Grid. But I want this column to be read Only. The grid should show checked/unchecked as per the data but should not allow to edit this checkbox. When I try to make the enable property to false, all the records a show checked, which is incorrect :(


Below is the code in the
radCBTransactionDetails_ItemCreated to check/uncheck the checkbox.

if (column.UniqueName == "IsIndividual" && column is GridTemplateColumn)
{
CheckBox chk = (CheckBox)e.Item.FindControl("chkboxIsIndividual");
// chk.Enabled = false;
if (gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["IsIndividual"].ToString().ToUpper().Equals("TRUE"))
{
chk.Checked = true;
//chk.Enabled = false;
editLink.Text = "ViewIndividual";
}
else if (gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["IsIndividual"].ToString().ToUpper().Equals("FALSE"))
{
chk.Checked = false;
//chk.Enabled = true;
editLink.Text = "Bulk";

}
}​

Please help me with this asap.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Aug 2014, 10:40 AM
Hi Kalpana,

You can use the GridCheckBoxColumn to achieve your requirement instead of Checkbox in GridTemplateColumn. When the grid is in browser mode, or if the column is read-only, the check box is disabled. When the column is editable, the check box is enabled. 

Thanks,
Shinu
0
Kalpana
Top achievements
Rank 1
answered on 14 Aug 2014, 11:40 AM
Dear Shinu

Thanks a lot for your quick Reply.
I tried using GridCheckBoxColumn inside the RadGrid, the checkbox appears diabled but the data is incorrect. All the checkboxes appeared as checked.

In .aspx page

<telerik:GridCheckBoxColumn DataField="IsIndividual" DataType="System.Boolean" UniqueName="IsIndividual" HeaderText="IsIndividual" ItemStyle-Width="11%"> <ItemStyle Width="11%" /></telerik:GridCheckBoxColumn>

And I am making it checked/unchecked in the  radCBTransactionDetails_ItemDataBound event

protected void radCBTransactionDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
CBTPSDAL.usp_GetCBTransactionDetailsByUserResult row = (CBTPSDAL.usp_GetCBTransactionDetailsByUserResult)item.DataItem;
CheckBox chk = (CheckBox)item["IsIndividual"].Controls[0];
string value = row.IsIndividual.ToString();
if (value.ToString().ToUpper() == "TRUE" || (value == "1"))
{
chk.Checked = true;
// chk.Enabled = true;
}
else
{
chk.Checked = false;
// chk.Enabled = true;
}
}
}

I want the checked/or unchecked in accordace with the bit data in the DB ans also disabled in the Grid. Awating for your reply :)

Thanks
Kalpana
0
Shinu
Top achievements
Rank 2
answered on 18 Aug 2014, 03:40 AM
Hi Kalpana,

The GridCheckBoxColumn will bind to the data according to values in db. You do not have to bind it in the ItemDataBound event again. This binds to the column set in DataField property. Please take a look at the screenshot of the result.

ASPX:
<telerik:RadGrid ID="rgrdSample" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" AllowPaging="true" AutoGenerateEditColumn="true">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="IsTrue" DataType="System.Boolean" UniqueName="IsTrue" HeaderText="IsTrue">
            </telerik:GridCheckBoxColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

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