This is a migrated thread and some comments may be shown as answers.

[Solved] GridButtonColumn not displayed when Item is Selected

2 Answers 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fabian
Top achievements
Rank 1
Fabian asked on 06 May 2009, 10:22 AM

Hello Support,

I use the Grid to Display a Advanced SearchResult in a Tooltip. With the GridButtonColumn, the user should select a Item of the Resultset, in ItemCommand Event the selected Item is set  to the selected Value of a ComboBox.

This All works fine, but after selecting a Item with the GridButtonColumn, the Grid highlights the Row, and the GridButtonColumn not displays anymore.

I want to highlight the Row and show the ButtonColumn. If I Rebuild the Grid the Row is not selected anymore, the Button is shown again.

Build the Grid Serverside, is calling after a SearchButton Clicked

 
protected void BuildFilterPreviewGrid(ArrayList columnList) 
        { 
            rdgPreview.Columns.Clear(); 
            foreach (string columnName in columnList) 
            { 
                Telerik.Web.UI.GridBoundColumn thisCol = new GridBoundColumn(); 
                thisCol.HeaderText = columnName; 
                thisCol.DataField = columnName; 
 
                if (columnName == DataValueField) 
                    thisCol.Visible = false
 
                rdgPreview.Columns.Add(thisCol); 
            } 
 
            Telerik.Web.UI.GridButtonColumn thisButtonCol = new GridButtonColumn(); 
            thisButtonCol.UniqueName = "lbtSelect"
            thisButtonCol.CommandName = "SelectColumn"
            thisButtonCol.Text = "auswählen"
            thisButtonCol.ButtonType = GridButtonColumnType.LinkButton; 
            thisButtonCol.Display = true
            thisButtonCol.ShowInEditForm = true
 
 
         
         
            rdgPreview.Columns.Add(thisButtonCol); 
 
 
 
            if (DataSource != null
            { 
                string RowFilter = string.Empty; 
 
                if (((List<RowFilterObject>)RowFilterList).Count > 0) 
                    RowFilter = RowFilterObject.GetRowFilter((List<RowFilterObject>)RowFilterList); 
 
                DataSource.DefaultView.RowFilter = (!string.IsNullOrEmpty(RowFilter)) ? "(" + RowFilter + ")" : RowFilter; 
 
                if (AdvancedFilterString != string.Empty) 
                { 
                    if (DataSource.DefaultView.RowFilter != string.Empty) 
                        DataSource.DefaultView.RowFilter += " AND (" + AdvancedFilterString + ")"
                    else 
                        DataSource.DefaultView.RowFilter = AdvancedFilterString; 
 
 
                } 
                string[] distinctColumns = (string[])columnList.ToArray(typeof(string)); 
 
                DataTable distinctValues = DataSource.DefaultView.ToTable(true, distinctColumns).Copy(); 
 
                distinctValues.DefaultView.Sort = DataTextField + " ASC"
 
                rdgPreview.DataSource = distinctValues.DefaultView; 
                rdgPreview.DataBind(); 
            } 
        } 


Grid Events

 void rdgPreview_PageIndexChanged(object source, GridPageChangedEventArgs e) 
        { 
            rdgPreview.CurrentPageIndex = e.NewPageIndex; 
 
            DoAdvancedFilter(); 
        } 
        void rdgPreview_ItemCommand(object source, GridCommandEventArgs e) 
        { 
 
            if (e.CommandName.ToLower() == "selectcolumn"
            { 
                string arg = e.CommandArgument.ToString(); 
                 
                e.Item.Selected = true
 
                SelectedValue = arg; 
 
                BuildAdvancedFilterControl(); 
            } 
        } 
 
        void rdgPreview_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
             
            if (e.Item is GridDataItem) 
            { 
//                GridDataItem dataitem = (GridDataItem)e.Item; 
 
                System.Web.UI.WebControls.LinkButton thisButton = e.Item.Cells[e.Item.Cells.Count - 1].Controls[0] as System.Web.UI.WebControls.LinkButton; 
 
                if (thisButton != null
                { 
                    thisButton.CommandArgument = ((DataRowView)e.Item.DataItem)[DataValueField].ToString(); 
                    thisButton.CommandName = "SelectColumn"
                } 
            } 
 
             
        } 


<div id="divOuter" runat="server"
    <div id="divDropDown" runat="server"
        <telerik:RadComboBox ID="ddlDropdown" runat="server" Skin="Gray" Height="190px" AllowCustomText="True"  
            ShowToggleImage="True" ShowMoreResultsBox="true" AutoPostBack="false" EnableLoadOnDemand="True"  
            MarkFirstMatch="false" EnableVirtualScrolling="true" Width="206px"  
            DropDownWidth="450"
        </telerik:RadComboBox> 
         
        <asp:ImageButton ID="btnAdvancedFilter" runat="server" ImageUrl="~/images/icons_32x32_aktiv/filtern.gif"  Width="20px" Height="20px"  /> 
         
    </div> 
    <telerik:RadToolTip runat="server" ID="RadToolTip" ShowEvent="OnClick" ManualClose="true"  Height="500px"  Width="750px" 
                TargetControlID="btnAdvancedFilter" IsClientID="false"  OffsetY="4" Delay="1"  HideEvent="LeaveToolTip" 
                Animation="Resize" Position="BottomCenter" RelativeTo="Element" Skin="Telerik"
                <div style="text-align:left;"
                <asp:PlaceHolder ID="plhFilterControls" runat="server"></asp:PlaceHolder> 
                <div style="text-align:right;"
                <asp:Button ID="btnDoAdvancedFilter" CssClass="button" runat="server" Text="Filtern"/>&nbsp;<asp:Button ID="btnClear" runat="server" CssClass="button"  Text="zurücksetzen"/> 
                </div>   
                  <telerik:RadGrid ShowGroupPanel="false" AllowMultiRowSelection="false" AllowMultiRowEdit="false"  AutoGenerateColumns="false" ID="rdgPreview"  
                 AllowFilteringByColumn="false" AllowSorting="false" width="750px" height="300px" PageSize="10" 
                    ShowFooter="false" runat="server" Skin="WebBlue" GridLines="None" AllowPaging="true"
                    <pagerstyle mode="NextPrevAndNumeric" /> 
                    </telerik:RadGrid>                   
                </div> 
                </telerik:RadToolTip>  
                 
    <asp:RequiredFieldValidator ID="rvAjaxDropdown" ControlToValidate="ddlDropdown" EnableClientScript="false" 
        runat="server"></asp:RequiredFieldValidator> 
        <telerik:RadToolTipManager runat="server" ID="RadToolTipManager1"   Width="750px" Height="500px" 
                    RelativeTo="Element" Animation="Slide" Position="BottomCenter"  /> 
</div> 
 




2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 May 2009, 04:56 AM
Hi Fabian,

I guess you are trying to add the GridButtonColumn each and every time a PostBack occurs. To add a column dynamically to a RadGrid control that is declared in the ASPX page, use the Page_Load event handler. Columns and detail table should be added to the corresponding collection first, before the values for their properties are set. This is important because no ViewState is managed for the object before it has been added to the corresponding collection.

 Be sure to check that IsPostBack is false. Otherwise, you will end up adding the same objects to the RadGrid multiple times.

CS:

private
 void Page_Load(object sender, System.EventArgs e) 
 if ( !IsPostBack ) 
 { 
   GridButtonColumn btnColumn; 
 
   //Important: first Add column to the collection 
   btnColumn= new GridButtonColumn (); 
   this.RadGrid1.MasterTableView.Columns.Add(btnColumn); 
 
   //Then set properties 
   btnColumn.UniqueName = "lbtSelect"
   btnColumn.HeaderText = "Select"
 } 

Regards
Shinu


0
Fabian
Top achievements
Rank 1
answered on 12 May 2009, 04:53 PM
Hello Shinu,

I don't think that this is the Problem. The Grid is created without any Problem.

My Problem is, that after the Grid is created and I hit the Select Button, the Button not displays anymore as long as I have a selected Row in the grid.

The event calls correct, so the Button is there... at this time

I can not bound it in  Pageload, because I know the Data to show, only after a Search Event, and I don't want to bind the data always, because it is possible that the Containing Parent Control is many times on a Form. So It would be a bad performance if i bind all the relating Grids without needing.

My Custom UserControl is used as a Advanced Combobox where i can activate a Additional Filter, which is show in a ToolTip. After define  the Search Parameter an click "Search" the Grid Columns is created dynamicly for the Resultset and the datasource will bind.

All works fine and the "Select " Button is shown. Now I Select a Row with the Linkbutton, theTooltip close, and I put the selected value as Selected Value to the ComboBox. If I reopen the Tooltip now. The Row is still selected, and the Button is not displayed. Just after I do a new Search and Rebuild the Grid, the Button shows again.

I think it must be a Property or something else which produces that behavior.   Could that be?


I Just create and bind the Grid after a Button_Click event
    
     protected void btnDoAdvancedFilter_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                DoAdvancedFilter(); 
            } 
            catch (Exception ex) 
            { 
                base.Page.ShowError(ex.ToString()); 
            } 
        } 
 
 
private void DoAdvancedFilter() 
        {  
               string advancedFilter = string.Empty; 
 
                ArrayList columnlist = new ArrayList();                 
 
               //... Filterlogik.... 
 
                    AdvancedFilterString = advancedFilter; 
 
                    ddlDropdown.Items.Clear(); 
 
                    BuildFilterPreviewGrid(columnlist); 
 
                     
                    RadToolTip.Show(); 
                } 
        } 
        
 
    
 



Thanks in Advance

Fabian






Tags
Grid
Asked by
Fabian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Fabian
Top achievements
Rank 1
Share this question
or