I have added the one checkbox colum in the grid. I would like to make that column editbale and rest of the columns are not. how to make it ?, At the same time I want to capture the checkbox state changed event.
FYI : I am using the following code to add checkbox column
GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn();
checkBoxColumn.DataType =
typeof(bool);
checkBoxColumn.HeaderText =
string.Empty;
checkBoxColumn.Width = 25;
dGridDisplayField.MasterGridViewTemplate.Columns.Insert(0, checkBoxColumn);
Thanks you
Raghu
7 Answers, 1 is accepted
Thank you for contacting us.
You should set the ReadOnly property of all columns except the check box column to true. This will make them not editable.
As for capturing value-change event I suggest you to use the ValueChanged event of RadGridView to capture changes in grid values. Consider the following code snippet:
void grid_ValueChanged(object sender, EventArgs e) |
{ |
if (this.grid.ActiveEditor is RadCheckBoxEditor) |
{ |
bool value = (bool)this.grid.ActiveEditor.Value; |
} |
} |
I hope this helps.
All the best,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks for your Answer.
I have one more question regarding this.
I am not able set the the Header Text empty for this Check box column. If I set HeaderText = String.Empty, the value is not relfelecting.
Coming as Column1, if I set some other text the setted value is coming in the header.
Thanks
Raghu
Thank you for this question.
RadGridView uses the value of the UniqueName property as a default header text when the HeaderText is empty. You should set the HeaderText to a nonempty string (e.g. space) to override this behavior. Consider the following code:
this.radGridView1.Columns["Value"].HeaderText = " "; |
I hope this helps. Do not hesitate to write us if you have other questions.
Best wishes,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please help
GridCheckBoxColumn checkColumn = new GridCheckBoxColumn();
checkColumn.DataField =
"Selected";
checkColumn.DataType =
typeof(bool);
checkColumn.ReadOnly =
false ;
checkColumn.HeaderText =
" ";
RadGrid1.MasterTableView.Columns.Add(checkColumn);
I can't find any issues by looking at your code which to cause the issue you experience. Please open a support ticket and send me your application in order to investigate your case and locate the problem.
I am looking forward to your reply.
Sincerely yours,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Here's my code. I want to enable the checkbox so I can select and unselect it.
ASPX page
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MailingDetailsUc.ascx.cs" |
Inherits="SampleTelerik.MailingDetailsUc" %> |
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" |
Namespace="System.Web.UI" TagPrefix="asp" %> |
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> |
<asp:ScriptManager ID="ScriptManager1" runat="server"> |
</asp:ScriptManager> |
<telerik:RadGrid ID="RadGrid1" runat="server"> |
</telerik:RadGrid> |
Code Behind Code
protected void Page_Load(object sender, EventArgs e) |
{ |
DataTable table = new DataTable(); |
GridCheckBoxColumn checkColumn = new GridCheckBoxColumn(); |
checkColumn.DataField = "Selected"; |
checkColumn.DataType = typeof(bool); |
checkColumn.ReadOnly = false; |
checkColumn.HeaderText = ""; |
RadGrid1.MasterTableView.Columns.Add(checkColumn); |
table.Columns.Add("Selected", typeof(Boolean)); |
table.Columns.Add("Title", typeof(string)); |
table.Rows.Add(1,"Record 1"); |
table.Rows.Add(0,"Record 2"); |
table.Rows.Add(1, "Record 3"); |
table.Rows.Add(0, "Record 4"); |
table.Rows.Add(1, "Record 5"); |
RadGrid1.DataSource = table; |
RadGrid1.DataBind(); |
} |
For this purpose you can use either GridClientSelectColumn to check/select grid records or a template column with checkbox inside its ItemTemplate. Review the following online demos of the product for more details:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx
Additionally, I recommend you use advanced binding with NeedDataSource event handling:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx
instead of simple binding with DataBind() calls. Also note that there are conventions for runtime grid creation which has to be followed to ensure that the viewstate/lifecycle of the control will be consistent.
Kind regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.