
Thomas Dietz
Top achievements
Rank 1
Thomas Dietz
asked on 15 Feb 2011, 09:15 AM
Dear all,
how can I insert a command button in the grid header? The button should be linked to a javascript function on the client side.
The button should appear beside the column title.
Thanks!
how can I insert a command button in the grid header? The button should be linked to a javascript function on the client side.
The button should appear beside the column title.
Thanks!
4 Answers, 1 is accepted
0
Accepted

Shinu
Top achievements
Rank 2
answered on 15 Feb 2011, 10:00 AM
Hello Thomas,
You could add control to header dynamically in ItemCreated event of grid. The following forum shows how to do it.
Adding a checkbox to a header for a grid
Another option is using GridTemplateColumn, where you have HeaderTemplate option to customize the header of grid.
-Shinu.
You could add control to header dynamically in ItemCreated event of grid. The following forum shows how to do it.
Adding a checkbox to a header for a grid
Another option is using GridTemplateColumn, where you have HeaderTemplate option to customize the header of grid.
-Shinu.
0

Thomas Dietz
Top achievements
Rank 1
answered on 15 Feb 2011, 10:53 AM
Dear Shinu,
the code works, I have now a button in the grid header.
The next question is how to link this button to client side java code? it normally sends back a postback, but I disabled this postback. I simply want to set some presets in the columns without a server roundtrip.
...in the meantime i solved this with the OnClientClick Property.
Everything works! Thank you.
the code works, I have now a button in the grid header.
The next question is how to link this button to client side java code? it normally sends back a postback, but I disabled this postback. I simply want to set some presets in the columns without a server roundtrip.
...in the meantime i solved this with the OnClientClick Property.
Everything works! Thank you.
0

Carlos
Top achievements
Rank 1
answered on 22 Jul 2014, 07:56 PM
Please fix the link above.
0

Shinu
Top achievements
Rank 2
answered on 23 Jul 2014, 05:11 AM
Hi Carlos,
If you want to create a checkbox dynamically you can try the following code snippet or else you can use GridTemplateColumn as shown here
C#:
JS:
Thanks,
Shinu
If you want to create a checkbox dynamically you can try the following code snippet or else you can use GridTemplateColumn as shown here
C#:
protected
void
rgrdSample_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item;
CheckBox chksample =
new
CheckBox();
chksample.ID =
"chksample"
;
headerItem[
"ColumnUniqueName"
].Controls.Add(chksample);
chksample.Attributes.Add(
"onclick"
,
"checkheader();"
);
}
}
JS:
<script type=
"text/javascript"
>
function
checkheader() {
alert(
"Checked"
);
//Your code
}
</script>
Thanks,
Shinu