Hi, I really love radcontrols although i'm still using a trial version of asp.net ajax. I can't figure out how I can put imagebuttons on every row I have on my radgrid. These buttons will try to get the value of each row's "Name" field. I tried adding a gridbuttoncolumn but i can't add a handler to it and I don't know how to do it. Please help me. I'm in an urgent need.Thanks :)
16 Answers, 1 is accepted
0
RvdGrint
Top achievements
Rank 1
answered on 30 Jan 2012, 10:10 AM
Kugi,
In the columns section of the RadGrid you should add the following column:
You can handle the delete action from the ItemCommand event in the code-behind.
Regards,
Jos
In the columns section of the RadGrid you should add the following column:
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
FilterControlAltText
=
"Filter DeleteColumn column"
ImageUrl
=
"~/Images/RadGrid/16pxDelete.png"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
Resizable
=
"false"
ConfirmText
=
"Delete record?"
>
<
HeaderStyle
CssClass
=
"rgHeader ButtonColumnHeader"
></
HeaderStyle
>
<
ItemStyle
CssClass
=
"ButtonColumn"
/>
</
telerik:GridButtonColumn
>
You can handle the delete action from the ItemCommand event in the code-behind.
Regards,
Jos
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 10:30 AM
Hello,
or
Thanks,
Jayesh Goyani
<
MasterTableView
DataKeyNames
=
"ID"
Name
=
"Parent"
HierarchyLoadMode
=
"Client"
>
<
Columns
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
FilterControlAltText
=
"Filter DeleteColumn column"
ImageUrl
=
"~/Images/RadGrid/16pxDelete.png"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
Resizable
=
"false"
ConfirmText
=
"Delete record?"
>
<
HeaderStyle
CssClass
=
"rgHeader ButtonColumnHeader"
></
HeaderStyle
>
<
ItemStyle
CssClass
=
"ButtonColumn"
/>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
protected
void
RadGrid1_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
GridDataItem item = e.Item
as
GridDataItem;
// using columnuniquename
string
str1 = item[
"Name"
].Text;
// using DataKey
string
str2 = item.GetDataKeyValue(
"ID"
).ToString();
}
or
<
MasterTableView
DataKeyNames
=
"ID"
Name
=
"Parent"
HierarchyLoadMode
=
"Client"
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Delete"
CommandName
=
"Delete"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
Thanks,
Jayesh Goyani
0
Kugi
Top achievements
Rank 1
answered on 30 Jan 2012, 12:22 PM
Thanks for the quick replies.I tried the one jayesh gave,it almost worked but it seems the event wasn't handled.Am i suppose to add RadGrid1_DeleteCommand as eventhandler to something?
0
Kugi
Top achievements
Rank 1
answered on 30 Jan 2012, 12:40 PM
Nevermind, i added 'Handles gridsummary.DeleteCommand' and it worked. But there's still a problem,though I think could be on the other parts of my program. The first time i click the delete button,a dialog appears and if I click Ok it doesn't pass through RadGrid1_DeleteCommand (i have a break point there).Then click it again and no dialog will appear but it will now pass through the eventhandler....so what was that? LOL
Anyway, I want to make the confirm dialog better. I put 'ConfirmDialogType="RadWindow" ConfirmTitle=""' on the source but both wasn't reflected. The dialog that appeared is still normal and with 'loclhost...blah blah" on its title bar.
sorry for my long post,thank you very much. much appreciated :)
Anyway, I want to make the confirm dialog better. I put 'ConfirmDialogType="RadWindow" ConfirmTitle=""' on the source but both wasn't reflected. The dialog that appeared is still normal and with 'loclhost...blah blah" on its title bar.
sorry for my long post,thank you very much. much appreciated :)
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 02:15 PM
Hello,
Please add WindowManager in your page.
Thanks,
Jayesh Goyani
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
></
telerik:RadWindowManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
FilterControlAltText
=
"Filter DeleteColumn column"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
ConfirmDialogType
=
"RadWindow"
Resizable
=
"false"
ConfirmText
=
"Delete record?"
>
</
telerik:GridButtonColumn
>
Please add WindowManager in your page.
Thanks,
Jayesh Goyani
0
Kugi
Top achievements
Rank 1
answered on 30 Jan 2012, 02:32 PM
wow thanks it worked. But I still have the problem. I have to click the delete button twice before it execute radgrid_deletecommand :(
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 02:43 PM
Hello,
Which method you used for binding the data to RadGrid ?
Note : please use Advance data binding method for binding the grid data.
Thanks,
Jayesh Goyani
Which method you used for binding the data to RadGrid ?
Note : please use Advance data binding method for binding the grid data.
Thanks,
Jayesh Goyani
0
Kugi
Top achievements
Rank 1
answered on 30 Jan 2012, 03:17 PM
I added rows in a datatable and bind it with radgrid. I don't know any other way. Sorry I'm a beginner with these things.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Jan 2012, 03:27 PM
Hello,
Are you binding the data in "
OR
your C# code should be
Thanks,
Jayesh Goyani
Are you binding the data in "
NeedDataSource
" event or not ??OR
your C# code should be
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.Data;
public
partial
class
testaspnet : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
RadGrid1_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
dynamic data =
new
[] {
new
{ ID =
"1"
, Name =
"Name11"
,ParentID =
"0"
},
new
{ ID =
"2"
, Name =
"Name11"
,ParentID =
"1"
},
new
{ ID =
"3"
, Name =
"Name11"
,ParentID =
"2"
},
new
{ ID =
"4"
, Name =
"Name1"
,ParentID =
"3"
}
};
RadGrid1.DataSource = data;
}
protected
void
RadGrid1_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
}
}
Thanks,
Jayesh Goyani
0
Kugi
Top achievements
Rank 1
answered on 30 Jan 2012, 03:33 PM
Thank you very much! I fixed it by setting enableviewstate of the radgrid to false. Sorry I didn't really followed the advance databinding although I got the idea from your link. Whatever it is, I achieved what I want to happen. Thanks again :)
0
bharath
Top achievements
Rank 1
answered on 06 May 2014, 06:13 PM
HI ayesh i want to do add newrecord , Edit , delete of Rows for radgrid which is created dynamically.
i want to do it inline method.
/Bharath
i want to do it inline method.
/Bharath
0
bharath
Top achievements
Rank 1
answered on 06 May 2014, 06:19 PM
HI Jayesh i want to do add newrecord , Edit , delete of Rows for radgrid which is created dynamically.
i want to do it inline method.
i want to do it inline method.
0
Shinu
Top achievements
Rank 2
answered on 07 May 2014, 05:32 AM
Hi Bharath,
I'm not clear about your requirement, I guess you want to set the Edit, Delete and AddNewRecord button dynamically. Please take a look at the below code snippet, if this doesn't help elaborate on your requirement.
C#:
Thanks,
Shinu
I'm not clear about your requirement, I guess you want to set the Edit, Delete and AddNewRecord button dynamically. Please take a look at the below code snippet, if this doesn't help elaborate on your requirement.
C#:
protected
void
Page_Init(
object
source, System.EventArgs e)
{
RadGrid1 =
new
RadGrid();
//To have AddNewRecord
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
//To have Inline EditMode
RadGrid1.AutoGenerateEditColumn =
true
;
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;
//To have Delete
RadGrid1.AutoGenerateDeleteColumn =
true
;
// OR
//If you want ImageButton you can use this instead of AutoGenerateEditColumn
GridEditCommandColumn editColumn =
new
GridEditCommandColumn();
editColumn.ButtonType = GridButtonColumnType.ImageButton;
editColumn.UniqueName =
"EditColumn"
;
RadGrid1.MasterTableView.Columns.Add(editColumn);
//Similary for delete button
GridButtonColumn deleteColumn =
new
GridButtonColumn();
deleteColumn.ButtonType = GridButtonColumnType.ImageButton;
deleteColumn.CommandName = RadGrid.DeleteCommandName;
deleteColumn.UniqueName =
"DeleteColumn"
;
RadGrid1.MasterTableView.Columns.Add(deleteColumn);
}
Thanks,
Shinu
0
bharath
Top achievements
Rank 1
answered on 09 Sep 2014, 03:23 PM
hi,
i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.
i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error
autocompleteextender.TargetControlId with that textbox id is not found.
when the same textbox i added to the page (page.controls.Add(txt)) error is not coming but inside radgrid textbox is not working as
autocomplete Extender. Out side text box is working as autocompleteextender.
i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.
i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error
autocompleteextender.TargetControlId with that textbox id is not found.
when the same textbox i added to the page (page.controls.Add(txt)) error is not coming but inside radgrid textbox is not working as
autocomplete Extender. Out side text box is working as autocompleteextender.
0
bharath
Top achievements
Rank 1
answered on 09 Sep 2014, 03:24 PM
hi,
i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.
i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error
autocompleteextender.TargetControlId with that textbox id is not found.
when the same textbox i added to the page (page.controls.Add(txt)) error is not coming but inside radgrid textbox is not working as
autocomplete Extender. Out side text box is working as autocompleteextender.
i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.
i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error
autocompleteextender.TargetControlId with that textbox id is not found.
when the same textbox i added to the page (page.controls.Add(txt)) error is not coming but inside radgrid textbox is not working as
autocomplete Extender. Out side text box is working as autocompleteextender.
0
Hi Bharath,
The behavior experienced may be expected. The OnItemDataBound event is fired too later for adding controls programmatically. Please try moving the logic in the OnItemCreated event and test whether this resolves the problem. If it does not please share with us the markup and code-behind of the page so we could examine the exact implementation.
Regards,
Angel Petrov
Telerik
The behavior experienced may be expected. The OnItemDataBound event is fired too later for adding controls programmatically. Please try moving the logic in the OnItemCreated event and test whether this resolves the problem. If it does not please share with us the markup and code-behind of the page so we could examine the exact implementation.
Regards,
Angel Petrov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.