Search code examples
.nettelerik-griddatagridviewbuttoncolumn

Add two button columns to .NET web application telerik grid view


I am using a 'telerik grid view' in a .NET web project. I am using two 'Grid Button Columns' in that. The code in Default.aspx is as follows.

 <telerik:RadGrid ID="testGrid" runat="server" AutoGenerateColumns="false" GridLines="None">
                            <MasterTableView DataKeyNames="userID" AllowPaging="true" AllowSorting="true" PagerStyle-AlwaysVisible="true" PagerStyle-Mode="NextPrevNumericAndAdvanced">
                                <RowIndicatorColumn Visible="false"> 
                                    <HeaderStyle Width="20" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn Resizable="false" Visible="false">
                                    <HeaderStyle Width="20" />
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridBoundColumn HeaderStyle-Width="70px" DataField="SuserID" HeaderText="User ID"></telerik:GridBoundColumn>
                                </Columns>
                                <Columns >
                                    <telerik:GridBoundColumn  DataField="userName" HeaderText="User Name"></telerik:GridBoundColumn>
                                </Columns>
                                <Columns >   
                                <telerik:GridButtonColumn HeaderStyle-Width="30px" HeaderText="Test" Text="&lt;img src=images\edit1.gif border=0 align=absmiddle alt='Select this Item'&gt;"
                                        CommandName="Select">
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <Columns>
                                <telerik:GridButtonColumn HeaderStyle-Width="30px" HeaderText="Test 2" Text="&lt;img src=images\edit1.gif border=0 align=absmiddle alt='Select this Item'&gt;"
                                        CommandName="Select">
                                    </telerik:GridButtonColumn>
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid> 

Finally I included the following code in Default.aspx.vb file,

 Protected Sub testGrid_ItemCommand(source As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles testGrid.ItemCommand
    PoupMessage("testing confiremed !")
End Sub

Now when I click both of the button columns in the grid view, the same message pops up. I want to assign two tasks for the relevant buttons. How can I do that?


Solution

  • if I understand correctly change code as CommandName

    <telerik:GridButtonColumn HeaderStyle-Width="30px" HeaderText="Test" Text="&lt;img src=images\edit1.gif border=0 align=absmiddle alt='Select this Item'&gt;"
                                        CommandName="Select1">
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <Columns>
    <telerik:GridButtonColumn HeaderStyle-Width="30px" HeaderText="Test 2" Text="&lt;img src=images\edit1.gif border=0 align=absmiddle alt='Select this Item'&gt;"
                                        CommandName="Select2">
                                    </telerik:GridButtonColumn>
                                </Columns>
    

    And In ItemCommand Event

    If e.CommandName = "SELECT1 " Then
      //some code
    ElseIf e.CommandName = "SELECT2 " Then
           //some code
    End If