Some days ago, I asked a question to remove the header row and making a label with the header text on the filter row, and switching to the filter when the label is clicked, and going back to the label when the textbox blurs.
The code to achieve that is:
C#
Javascript:
CSS
But if I set the radgrid property AllowSorting to True, the label disappears, as the headercell does not contain any text (the label doesn't disappear, but its text is null). I know it is a hyperlink, but I cant get the href link with code behind.
How do I fetch the Sort function from the header cell, so I can put the function in a button right beside the label?
The code to achieve that is:
C#
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item is GridHeaderItem) { e.Item.Visible = false; e.Item.Display = false; } if (e.Item is GridFilteringItem) { GridHeaderItem header = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem; GridFilteringItem filterItem = e.Item as GridFilteringItem; for (int i = 0; i < header.Cells.Count; i++) { Label label = new Label(); label.Text = header.Cells[i].Text; if (filterItem.Cells[i].Controls.Count > 0) { TextBox textbox = filterItem.Cells[i].Controls[0] as TextBox; textbox.CssClass = "hidden"; Button button = filterItem.Cells[i].Controls[1] as Button; button.CssClass = "hidden"; filterItem.Cells[i].Controls.Add(label); label.Attributes.Add("onclick", "showFilterItem('" + label.ClientID + "','" + textbox.ClientID + "','" + button.ClientID + "')"); textbox.Attributes.Add("onblur", "hideFilterItem('" + label.ClientID + "','" + textbox.ClientID + "','" + button.ClientID + "')"); } } }}Javascript:
<script type="text/javascript"> //Put your JavaScript code here. function showFilterItem(labelID, textID, buttonID) { $get(labelID).className = "hidden"; $get(textID).className = "visible"; $get(buttonID).className = "visibleButton"; } function hideFilterItem(labelID, textID, buttonID) { $get(labelID).className = "visible"; $get(textID).className = "hidden"; $get(buttonID).className = "hidden"; }</script>CSS
<style type="text/css"> .hidden { display: none !important; } .visible { display: ""; margin-top: 0px; height: 10px; } .rcbArrowCell { display: none !important; } .rgFilterRow td { border-right: none !important; } .RadGrid .rgFilterRow .rcbInputCell { padding:0; border-width:0; } .visibleButton { display: ""; background-image: url('icon-filter.gif'); height: 16px; background-repeat: no-repeat; }</style>But if I set the radgrid property AllowSorting to True, the label disappears, as the headercell does not contain any text (the label doesn't disappear, but its text is null). I know it is a hyperlink, but I cant get the href link with code behind.
How do I fetch the Sort function from the header cell, so I can put the function in a button right beside the label?