8 Answers, 1 is accepted
You can set the CommandName for the GridButtonColumn. Attach the event onItemCommand to RadGrid and check for the e.commandName and write your code there. Here is a sample code.
aspx:
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
onitemcommand="RadGrid1_ItemCommand""
>
<
MasterTableView
DataKeyNames
=
"EmpId"
EditMode
=
"InPlace"
>
<
Columns
>
<
telerik:GridButtonColumn
CommandName
=
"Add"
Text
=
"Add"
UniqueName
=
"Add"
HeaderText
=
"Add"
>
</
telerik:GridButtonColumn
>
. . . . . . .
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"Add"
)
{
// your code
}
}
but how can i print that particular row.... using that button........?
I hope the following forum would help you to get started.
How to print selected RadGrid row and add new link button in Command Item Template
Regards,
Princy.
can u help me in this ....
java script
<script type="text/javascript">
function getOuterHTML(obj) {
if (typeof (obj.outerHTML) == "undefined") {
var divWrapper = document.createElement("div");
var copyOb = obj.cloneNode(true);
divWrapper.appendChild(copyOb);
return divWrapper.innerHTML
}
else
return obj.outerHTML;
}
function PrintRadGrid() {
var previewWnd = window.open('about:blank', '', '', false);
var sh = '<%= ClientScript.GetWebResourceUrl(dg_Shiplab.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",dg_Shiplab.Skin)) %>';
var shBase = '<%= ClientScript.GetWebResourceUrl(dg_Shiplab.GetType(),"Telerik.Web.UI.Skins.Grid.css") %>';
var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= dg_Shiplab.ClientID %>').get_element()) + "</body></html>";
previewWnd.document.open();
previewWnd.document.write(htmlcontent);
previewWnd.document.close();
previewWnd.print();
previewWnd.close();
}
</script>
I want to call this script in this event...
protected void dg_EditCommand1(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
<script> ?
}
}
Hi,
I am using telerik image button in my grid but I am not able to handle click event.
Actually the button is for star mark, when user click on that button then startmark will be filled(i.e. I will show another image and get that row information and store in database.
I Created one datatable dt and set datasourse= dt for rad grid
then I create one GridButtonColumn, but when user click on that button It goes to server but not fire RadGrid1_ItemCommand event
this is my radgrid data:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" GroupPanelPosition="Top" PageSize="50" Skin="Metro" AllowPaging="True" BorderStyle="None" ForeColor="#666666" OnItemCommand="RadGrid1_ItemCommand">
<GroupingSettings CollapseAllTooltip="Collapse all groups" />
<SortingSettings EnableSkinSortStyles="False" />
<ExportSettings FileName="Export Auction">
</ExportSettings>
<ClientSettings AllowRowHide="True" EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">
<Selecting EnableDragToSelectRows="False" />
</ClientSettings>
<MasterTableView EnableLinqGrouping="False" GroupsDefaultExpanded="False" HierarchyLoadMode="ServerBind">
<CommandItemSettings ShowExportToCsvButton="True" ShowExportToExcelButton="True" ShowExportToPdfButton="True" ShowExportToWordButton="True" />
<Columns>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandArgument="watch" CommandName="watch" FilterControlAltText="Filter watch column" HeaderText="W" ImageUrl="images/star-blank.png" Text="Add to Watchlist" UniqueName="watch">
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
<FooterStyle BackColor="#666666" BorderStyle="None" ForeColor="White" />
<HeaderStyle BackColor="#666666" BorderStyle="None" ForeColor="White" />
</telerik:RadGrid>
In Page load I create this table
DataTable dt=new DataTable();
dt.Columns.Add("Sr.", typeof(int));
dt.Columns.Add("Domain", typeof(string));
dt.Columns.Add("col1", typeof(string));
dt.Columns.Add("col2", typeof(string));
dt.Columns.Add("col3", typeof(string));
RadGrid1.DataSource=dt;
This is my itemCommand method
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "watch")
{
GridDataItem item = (GridDataItem)e.Item;
string domain = item["Domain"].ToString();
}
}
I tried to replicate the behavior you describe, however I was not able to. Please check out the attached sample I used for testing. The ItemCommand is fired as expected on my end.
I would appreciate it if you let me know what should be modified in the sample in order to replicate the behavior you are seeing.
Regards,
Viktor Tachev
Telerik by Progress