how can i have instead of the texto na icon.
i tried this but this gives me na js error saying that need page eventvalidation true.
so there must be a way to but na image in edit delete instead of text
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateDeleteColumn
=
"True"
AutoGenerateEditColumn
=
"True"
CellSpacing
=
"0"
GridLines
=
"None"
Skin
=
"Metro"
AllowAutomaticDeletes
=
"True"
AllowAutomaticUpdates
=
"True"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
>
<
ClientSettings
AllowColumnHide
=
"True"
AllowKeyboardNavigation
=
"True"
>
<
Selecting
AllowRowSelect
=
"True"
/>
<
KeyboardNavigationSettings
AllowActiveRowCycle
=
"True"
AllowSubmitOnEnter
=
"True"
/>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
/>
</
ClientSettings
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridButtonColumn
ConfirmText
=
"Apagar utilizador?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
ItemStyle
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
<
EditFormSettings
ColumnNumber
=
"2"
CaptionDataField
=
"UserName"
CaptionFormatString
=
"Editar propriedades do utilizador {0}"
InsertCaption
=
"New Product"
>
<
FormTableItemStyle
Wrap
=
"False"
></
FormTableItemStyle
>
<
FormCaptionStyle
CssClass
=
"EditFormHeader"
></
FormCaptionStyle
>
<
FormMainTableStyle
GridLines
=
"None"
CellSpacing
=
"0"
CellPadding
=
"3"
Width
=
"100%"
></
FormMainTableStyle
>
<
FormTableStyle
CellSpacing
=
"0"
CellPadding
=
"2"
Height
=
"110px"
>
</
FormTableStyle
>
<
FormTableAlternatingItemStyle
Wrap
=
"False"
></
FormTableAlternatingItemStyle
>
<
EditColumn
ButtonType
=
"ImageButton"
UpdateText
=
"Actualizar"
UniqueName
=
"EditCommandColumn1"
CancelText
=
"Cancelar"
>
</
EditColumn
>
<
FormTableButtonRowStyle
HorizontalAlign
=
"Right"
CssClass
=
"EditFormButtonRow"
></
FormTableButtonRowStyle
>
</
EditFormSettings
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
Created
=
"True"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
AlwaysVisible
=
"True"
></
PagerStyle
>
</
MasterTableView
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
AlwaysVisible
=
"True"
></
PagerStyle
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
20 Answers, 1 is accepted

I guess you want Image button instead of the text.I see that you are using AutoGenerateDeleteColumn="true" AutoGenerateEditColumn="true" along with GridButtonColumn for Delete and GridEditCommandColumn. This is causing the issue.Since you want to set an Image Icon please use only the following code. Remove AutoGenerateDeleteColumn="true" AutoGenerateEditColumn="true" from the code.
ASPX:
<
telerik:GridButtonColumn
ConfirmText
=
"Apagar utilizador?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
ItemStyle
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridEditCommandColumn
>
Hope this helps.
Let me know if any concern.
Thanks,
Princy


Make sure that you are using Advanced data binding using NeedDataSource event. Also Paging with disabled control ViewState is not supported. Try setting EnableViewState property of the RadGrid / MasterTableView is set to true.
Thanks,
Princy

sorry i'm new to telerik elememts...
also i have some coluns that shows true/false i i want to replace it with a checkbox, and just allow to change it in edit mode
so i have made this:
<telerik:GridCheckBoxColumn DataField="Aproved" HeaderText="Aproved" SortExpression="Aproved"
UniqueName="Aproved" EditFormColumnIndex="1">
</telerik:GridCheckBoxColumn>--%>
however it instead of replace the actual aproved col adds a news one so i stay with 2 coluns one says true false and other shows the checkbox
I want just the checkbox. same behave with is locked out col.
also in roles I want to show all the roles that exits but just have on checkboxlist maked the one's wich is associated with user
username and created date must be a label in edit mode.
data must be updated when clicking the update button , how to fetch that event?
also icons are no aligned all it the same way when took the auto.-generated and approved checkbox are not as the others
and how can I take the true false coluns from grid but pay attention that if I take the true false col. the checkbox col will not mark the checkbox so I think I need to hide a coluns by its index
also need command name or similar(because I cant find the property) to make the delete command went in codebehind to delete the row
by the way radgrid will update the data when clickon update button or do I need to specify update command
also I want to hide a user "root" from grid
http://s17.postimg.org/kzv1l7nlb/Sem_T_tulo3.png

I'm not clear with all your requirements.Please read through and let me know if any concern.
1)In order to make a checkbox column instead of Approved and Is Locked out,one way is to hide that column in the PreRender event.Please try the following code:
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.GetColumn(
"ColumnName"
).Visible =
false
;
}
2)Then on the update button click the UpdateCommand will be fired and you have to write respective code for updation if you are not using Automatic CRUD Operation .
ASPX:
<
EditColumn
ButtonType
=
"ImageButton"
UpdateText
=
"Update"
UniqueName
=
"EditCommandColumn1"
CancelText
=
"Cancel"
>
</
EditColumn
>
C#:
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
//Your code for Updation
}
3)When using the button for delete you can set the CommandName for the function you are performing.Then in ItemCommand or DeleteCommand you can access that button.You can set the HeaderStyle-Width property in the column if not visible fully.
Note that,in case if you are using CommandName as Delete,it perform the delete operation,but if you are giving any other name,it can be accessed only through ItemCommand Event as shown below:
ASPX:
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this product?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"DeleteRow"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
HeaderStyle
Width
=
"100px"
/>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
></
ItemStyle
>
</
telerik:GridButtonColumn
>
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName==
"DeleteRow")
{
//Code to Delete
}
}
4)I see that you want to set two column not to be editable,that is instead of setting it as label.Please try the below code:
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
(e.Item
as
GridEditableItem)[
"ColumnName"
].Enabled =
false
;
}
}
5)If you want to hide a particular row you can use the following code snippet.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem items=(GridDataItem)e.Item;
string
user=items[
"UserName"
].Text;
if
(user ==
"root"
)
{
items.Display =
false
;
}
}
}
I hope these points might help you.
Thanks,
Princy

i'm using this to make the checkbox
<telerik:GridCheckBoxColumn DataField="Aproved" HeaderText="Aproved" SortExpression="Aproved"
UniqueName="Aproved" EditFormColumnIndex="1" ItemStyle-HorizontalAlign ="Left">
</telerik:GridCheckBoxColumn>
and then in code behind this
dr["Aproved"]
MembershipUser.isAproved
so checkboxcloumn is searching from this approved name and transform it to checkbox but can it be binded directly on the above code when creating column
and how can I show in edit mode rolename a checkbox list with all roles but the checkbox just marks if the user is in that role , so I need to take that textboc and replace by checkboxlist
approved checkbox on edit mode is misaligned with other items as you see in image, the update and cancel icons I already align them
code to hide works but it "breaks" the layout because we have a gray cell and then a white with hiding we have two white cells and then a gray one so its easy to understand that is hidden something... any fix?
2) i'm using automatic updates and delete but I'm binding datasource on needdatasource event and when I click on update button nothing happends.
also i'm allowing e-mail change but it must verify before save it if there is an equal email on db it there is pop a message

Since you are adding the GridCheckBoxColumn declaratively,i don't think it is possible to do from code behind.
Then you want to set a column as checkboxlist in edit mode.Please try the below code snippet.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
foreach
(GridColumn col
in
RadGrid1.MasterTableView.AutoGeneratedColumns)
{
if
(col.DataType ==
typeof
(
string
))
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
TextBox txt = (TextBox)item[col.UniqueName].Controls[0];
string
value = txt.Text;
txt.Visible =
false
;
if
(col.UniqueName ==
"RoleName"
)
{
CheckBoxList checks =
new
CheckBoxList();
checks.SelectedValue = value;
checks.DataSourceID =
"SqlDataSource1"
;
checks.DataTextField =
"RoleName"
;
checks.DataValueField =
"RoleName"
;
checks.ID =
"lnk"
+ Guid.NewGuid();
item[col.UniqueName].Controls.Add(checks);
}
}
}
}
}
Then your issue on misalignment of the approved column is because you have set EditFormColumnIndex="1",please remove that and see or make its value "0" to get the alignment correct.
Then when using Automatic CRUD operation make sure that you do according to what is shown in this demo.crud means create,read,update and delete.Automatic crud means without handling anything manually from code behind.
Then in order to verify the email you could try querying the database into the InsertCommand and check if the value into the email variable already exists into some record. If it exists you could cancel the InsertCommand.
Thanks,
Princy

what about the style "break" while hiding a row because the normal view is one line gray and one white now I have two whites because one gray is hidden.
another thing if I take that checkbox declarative could I add it in code-behind and make it check if approved or not and hide the true false col?
so I need to add the checkbox and do not enable it in item template but only in edit mode that why I think checkgridcoulumn its easy

for (int i = 0; i < clbIncludes.Items.Count; i++) if (clbIncludes.GetItemCheckState(i) == CheckState.Checked) // Do selected stuff else // Do unselected stuff

if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if ((col.UniqueName == "Aproved") || (col.UniqueName == "IsLockedOut"))
{
CheckBox cb = new CheckBox();
cb.ID = "lnk" + Guid.NewGuid();
item[col.UniqueName].Controls.Add(cb);
}
now I need to fetch the value of it like gridcheckboc clomun does and hide that true/false

You mentioned you are using Automatic CRUD operation, then I'm not sure about the using of UpdateCommand in your code,for you requirements,its better to apply Manual CRUD operation.Please try the below code to get the checkboxlist selected data in update command.
C#:
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
string
values=
string
.Empty;
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem data = (GridEditableItem)e.Item;
CheckBoxList checkedItems = (CheckBoxList)data.FindControl(
"CheckBoxList1"
);
//Accessing the CheckBoxList
for
(
int
i = 0; i <checkedItems.Items.Count; i++)
{
if
(chk.Items[i].Selected)
{
values = values +
","
+ checkedItems .Items[i].Text.ToString();
//Storing the selected values
}
}
string
selectedvalue = values.Trim(
','
);//To trim off the last ','
}
}
To access the CheckBoxColumn in editmode in code behind you can try the below code snippet.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editdata = (GridEditableItem)e.Item;
CheckBox check = (CheckBox)editdata[
"Aproved"
].Controls[0];
if
(check.Checked)
{
//Your Code
}
}
}
Thanks,
Princy

so if I make this:
<telerik:GridCheckBoxColumn DataField="Aproved" HeaderText="Aproved" SortExpression="Aproved"
UniqueName="Aproved" >
</telerik:GridCheckBoxColumn>
it create a checkbox an auto-checks if true or not
when I change to this:
I think I need to set client.idmode to static in code behind of that checkbox list otherwise when o run that code to check the values in update command it gives Object reference not set to an instance of an object."} because I have a content place holder
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if ((col.UniqueName == "Aproved") || (col.UniqueName == "IsLockedOut"))
{
CheckBox cb = new CheckBox();
cb.ID = "lnk" + Guid.NewGuid();
item[col.UniqueName].Controls.Add(cb);
}
the checkbox column instead of true/false appears the checkbox but no one is marked with the check so its not getting my custom datasource
with frist option it leaves the true/false column and add another one called also approved with checkbox

GridCheckBoxColumn by its nature will be disabled in the view mode. And will be enabled in the edit mode. From your code I have seen that you are assigning a DataField="Aproved" for the GridCheckBoxColumn. So the GridCheckBox column will be either checked or unchecked depending o the value of the DataField. In case if you want to change the value, you can do it in edit mode and update to database.
I am not sure about what you want to accomplish. Can you please specify the following,
1. Why you are adding a CheckBox to the 'Aproved' and 'IsLockedOut'?
2.What do you mean by the custom datasource.
Here is the complete code I have tried to add CheckBoxList to the field RoleName in edit mode and retrieving its value in UpdateCommand.Please change the "cb.ID = "lnk" + Guid.NewGuid();" to "CheckBoxList1" as I have mentioned in the above code and try the below code snippet.
C#:
//To create the CheckBoxList in Edit Mode
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
foreach
(GridColumn col
in
RadGrid1.MasterTableView.AutoGeneratedColumns)
{
if
(col.DataType ==
typeof
(
string
))
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
TextBox txt = (TextBox)item[col.UniqueName].Controls[0];
//Access the textbox in editmode
string
value = txt.Text;
if
(col.UniqueName ==
"RoleName"
)
{
txt.Visible =
false
;
CheckBoxList checks =
new
CheckBoxList();
checks.DataSourceID =
"SqlDataSource1"
;
checks.DataTextField =
"RoleName"
;
checks.DataValueField =
"RoleName"
;
checks.ID =
"CheckBoxList1"
;
item[col.UniqueName].Controls.Add(checks);
}
else
{
txt.Visible =
true
;
}
}
}
}
}
//To make the CheckBoxList select the respective value
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
foreach
(GridColumn col
in
RadGrid1.MasterTableView.AutoGeneratedColumns)
{
if
(col.DataType ==
typeof
(
string
))
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
TextBox txt = (TextBox)item[col.UniqueName].Controls[0];
string
value = txt.Text;
if
(col.UniqueName ==
"RoleName"
)
{
txt.Visible =
false
;
CheckBoxList chk = (CheckBoxList)item.FindControl(
"CheckBoxList1"
);
chk.SelectedValue = value;
}
}
}
}
}
//Update command to get the values of CheckBoxList
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
string
values=
string
.Empty;
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem data = (GridEditableItem)e.Item;
CheckBoxList chk = (CheckBoxList)data.FindControl(
"CheckBoxList1"
);
for
(
int
i = 0; i < chk.Items.Count; i++)
{
if
(chk.Items[i].Selected)
{
values = values +
","
+ chk.Items[i].Text.ToString();
//Storing the selected values
}
}
string
selectedvalue = values.Trim(
','
);
}
}
Thanks,
Princy

I have this custom dataset http://forums.asp.net/t/1887907.aspx/1 and the problem is it creates an colluns called approved with true/false instead of checkbox. if I create a checkbox col manually it replace that column with the checkbox but don't bind it with any value (checked/unchecked) juts in edit mode.
if I add a gridcheckboc clomun it will stay will the true/false column and this new one with the checkboxes here they showed on the gridtemplateand edit mode with values in both.
I could try to hide a column by its index, since in the last option the two column have same name. how could I hide it
also I need to fix when hide a row it insetad of make a row gray and white it stays with 2 white
how could then I fetch the email etxtbox and this checkbox clomun values in update?
also the checkboxlist gives me an error I think I have to use clientidmode because I have all things inside a content place holder and this could cause the error
I have changed the name to CBLRole but it gives me that error maybe because is in contentplaceholder

I have add a gridcheckbox column and hide on pre-render the other column that fine but in edit mode the other one stills appear.
the way to get checkboxlist checks still get error on update button click
need to fetch textbox and this new checks on update also.
if you know other way to make the checkbox work like gridcheckbox col(bind it and just editable in edit mode) because as I said before ifi add it manually it wont bind any value in template just on edit mode
update2.
it wont find CBLRole because it needs to use client.idmode=static but I don't know how to set it in code-behind since client id property don't give any option, now it gives this:
ctl00_ContentPlaceHolderMain_RadGrid1_ctl00_ctl07_CBLRole_0
update3
I have added
checks.ClientIDMode = ClientIDMode.Static;
but it enumerates the options like cblrole_1 ; cblrole_2 etc and don't finde cblrole

In order to hide the column,please try the following code snippet.
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
// Hide Column in view mode
RadGrid1.MasterTableView.GetColumn(
"Aproved"
).Visible =
false
;
}
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
//Hide Column in edit mode
if
(e.Item.IsInEditMode && e.Item
is
GridEditFormItem)
{
(e.Item
as
GridEditableItem)[
"Aproved"
].Parent.Visible =
false
;
}
}
The rest of the issue ,i wasn't able to replicate,its working fine at my end,even after placing in place holder.Can you share the full code you have tried,so that your requirements are more clear and help you out with the issues.
Thanks,
Princy

now its just the problema to fetch the data . and the "style break" problem when hidding a user it stays with two rows in white instead of one white and one gray.
how can i fetch teh data in the textbox in edit mode so there i can understtod if the problwm is with that part of the checkboxlist or not

Please have a look into this documentation on Accessing Cells and Rows ,it shows how to fetch the data in textbox in edit mode.
Hope this helps you.
Thanks,
Princy
