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

Selection problem

4 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FEST
Top achievements
Rank 1
FEST asked on 06 Jul 2011, 11:42 AM
Hi! I have tried to understand grid basics by following the demos in the website but i can't get the selection right. I'm trying to select an item by selecting a row (i'm not sure that is possible), and i even tried to creat a column (GridButtonColumn) where i set the button as image button and the imageurl for the image i want but i can't get it right, cause it is always appearing a checkbox instead of the image and, althought it selectes the row it does not selects the item in the row (i put a breakpoint in the grid_SelectedItemChanged and it doesn't do anything).
I also tried to do this as an gridtemplatecolumn and it makes appear the image i want but every time i click on it, instead of selecting the row and the item, it gives me an error witch i don't really know whatit means.


Code for the gridButtoncolumn (and grid):
<telerik:RadGrid runat="server"
      style="z-index: 1; left: 10px; top: 450px; position: absolute" 
      CellSpacing="0" DataSourceID="processos" 
      GridLines="None" ID="rg_processos" AutoGenerateColumns="False">
      <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
      </headercontextmenu>
      <mastertableview 
      datasourceid="processos">
      <commanditemsettings exporttopdftext="Export to PDF" />
      <rowindicatorcolumn 
      filtercontrolalttext="Filter RowIndicator column">
      <HeaderStyle Width="20px" />
      </rowindicatorcolumn>
      <expandcollapsecolumn 
      filtercontrolalttext="Filter ExpandColumn column">
         <HeaderStyle Width="20px" />
         </expandcollapsecolumn>
         <Columns>
         <telerik:GridClientSelectColumn ButtonType="ImageButton" 
         FilterControlAltText="Filter column1 column" 
         ImageUrl="~/images/select_16_mouse.png" Text="Seleccionar" UniqueName="column1">
                  </telerik:GridClientSelectColumn>
                  <telerik:GridBoundColumn DataField="Sinistrado_ID" DataType="System.Int32" 
                       FilterControlAltText="Filter Sinistrado_ID column" 
                       HeaderText="Sinistrado_ID" SortExpression="Sinistrado_ID" 
                       UniqueName="Sinistrado_ID">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="Data_sinistro" DataType="System.DateTime" 
                       FilterControlAltText="Filter Data_sinistro column" HeaderText="Data_sinistro" 
                       SortExpression="Data_sinistro" UniqueName="Data_sinistro">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="Nome" 
                       FilterControlAltText="Filter Nome column" HeaderText="Criado/Alterado" 
                       SortExpression="Nome" UniqueName="Nome">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="quando" DataType="System.DateTime" 
                       FilterControlAltText="Filter quando column" HeaderText="Criado/Alterado" 
                       SortExpression="quando" UniqueName="quando">
                       </telerik:GridBoundColumn>
                       </Columns>
                       <editformsettings>
                       <editcolumn 
                filtercontrolalttext="Filter EditCommandColumn column">
                    </editcolumn>
                    </editformsettings>
                    </mastertableview>
                    <clientsettings>
                    <selecting allowrowselect="True" />
                    </clientsettings>
                    <filtermenu enableimagesprites="False">
                    </filtermenu>
                </telerik:RadGrid>

code for the gridtemplatecolumn:
<Columns>
   <telerik:GridTemplateColumn ItemStyle-VerticalAlign="Middle" >
   <ItemTemplate>
   <asp:ImageButton runat="server" ImageUrl="~/images/select_16_mouse.png" />
   </ItemTemplate>
   </telerik:GridTemplateColumn>
   <telerik:GridClientSelectColumn ButtonType="ImageButton" 
   FilterControlAltText="Filter column1 column" 
   ImageUrl="~/images/select_16_mouse.png" Text="Seleccionar" UniqueName="column1">
   </telerik:GridClientSelectColumn>
      <telerik:GridBoundColumn DataField="Sinistrado_ID" DataType="System.Int32" 
      FilterControlAltText="Filter Sinistrado_ID column" 
      HeaderText="Sinistrado_ID" SortExpression="Sinistrado_ID" 
      UniqueName="Sinistrado_ID">
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="Data_sinistro" DataType="System.DateTime" 
      FilterControlAltText="Filter Data_sinistro column" HeaderText="Data_sinistro" 
      SortExpression="Data_sinistro" UniqueName="Data_sinistro">
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="Nome" 
       FilterControlAltText="Filter Nome column" HeaderText="Criado/Alterado" 
       SortExpression="Nome" UniqueName="Nome">
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="quando" DataType="System.DateTime" 
      FilterControlAltText="Filter quando column" HeaderText="Criado/Alterado" 
      SortExpression="quando" UniqueName="quando">
      </telerik:GridBoundColumn>
      </Columns>

One more thing, i only know vb.net and not very much. I can handle html so if possible and the solution calls for code i would appreciate for it to be in vb.net, if is as to be in c# or javascript so be it.

Thanks,
FEST

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Jul 2011, 12:39 PM
Hello Fest,

After examining your code I suppose you want to enable row selecting with GridButtonColumn. If that is the requirement, you can use GridButtonColumn with CommandName as "Select" which selects a particular row. On the other hand, GridClientSelectColumn acts like a GridButtonColumn with its CommandName set to "Select" or "Deselect": This column type lselects or deselects grid rows automatically by checking or unchecking the check box.

aspx:
<telerik:GridButtonColumn Text="Select" CommandName="Select" ButtonType="ImageButton" ImageUrl="~/images/select_16_mouse.png">
</telerik:GridButtonColumn>
<telerik:GridClientSelectColumn>
</telerik:GridClientSelectColumn>
   <ClientSettings>
    <Selecting AllowRowSelect="true" />          
   </ClientSettings>

Also check the following help documenation which explains this.
Column types.

Thanks,
Princy.
0
FEST
Top achievements
Rank 1
answered on 06 Jul 2011, 02:09 PM
Hi Princy!

Thanks a lot for the help that code put things working at least the part of the image, selection of row. Do you have any ideia how can i catch the event RowSelection with vb.net code so i can do things with the data? as i said the other time i only see the SelectedItemChanged. Maybe there is a way to connect the row selection to the respective item selection so the SelectedItemChanged can be fired and catched.

I'm realy sorry if i'm sounding like a noob :S

Many thanks,
Fábio
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Jul 2011, 05:11 AM
Hello Fest,

You can hook the event ItemCommand and catch the event by checking for the command name.
VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = RadGrid.SelectCommandName Then
       //your code
    End If
End Sub

Thanks,
Princy.
0
FEST
Top achievements
Rank 1
answered on 07 Jul 2011, 02:38 PM
Hi Princy! thanks for the information. I managed to make it work. I was receiving an odd error but i managed to fix as it had nothing to do with radojects. Thanks again, im closing the thread for now.
Tags
Grid
Asked by
FEST
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
FEST
Top achievements
Rank 1
Share this question
or