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

Disabled RadButton inside of RadGrid using OnItemCommand

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avihai
Top achievements
Rank 1
Avihai asked on 31 Mar 2014, 03:01 AM
Hello,

This is my RadGrid and I have RadButton inside of it, the thing is I want that the RadButton will be disabled for every click on the button.
(there is a button for each row inside of the RadGrid.)

The result that I'm getting for now is the RadButton only disabled one time instead of each row/click.

how can I do it for each click of the user on the button?




<telerik:RadGrid
         ID="rgOfficersToCallIn"
         runat="server"
         AutoGenerateColumns="False"
         AllowPaging="True"
         AllowSorting="True"
         PageSize="17"
         CellSpacing="0" GridLines="None"
         OnSortCommand="rgOfficersToCallIn_SortCommand"
         OnPageIndexChanged="rgOfficerToCallIn_PageIndexChanged"
         EnableHeaderContextFilterMenu="True" 
         Width="1200px"
         Height="640px">
            <ClientSettings EnablePostBackOnRowClick="true">              
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="true" UseStaticHeaders="True" SaveScrollPosition="true" />
            </ClientSettings>
            <MasterTableView ShowHeadersWhenNoRecords="true" NoMasterRecordsText="No Employees Records to display" GridLines="None" ItemStyle-Height="23px" Font-Size="11px" TableLayout="Auto">
                <PagerStyle Mode="NumericPages" AlwaysVisible="true"></PagerStyle>
                <Columns>             
                    <telerik:GridBoundColumn HeaderText="HR EmployeeID" HeaderStyle-Width="120px" Display="false" DataField="HREmployeeID" FilterControlWidth="40px" ShowFilterIcon="false" SortExpression="HREmployeeID"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Employee Number" HeaderStyle-Width="100px" DataField="EmployeeNumber" FilterControlWidth="95px" ShowFilterIcon="false" SortExpression="EmployeeNumber"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="First Name" HeaderStyle-Width="70px" DataField="FirstName" FilterControlWidth="105px" ShowFilterIcon="false"  SortExpression="FirstName"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Last Name" HeaderStyle-Width="70px" DataField="LastName" FilterControlWidth="84px" ShowFilterIcon="false"  SortExpression="LastName"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="City" HeaderStyle-Width="90px" DataField="City" FilterControlWidth="78px" ShowFilterIcon="false" SortExpression="City"></telerik:GridBoundColumn>
                   <%-- <telerik:GridBoundColumn HeaderText="Guard Card Number" HeaderStyle-Width="110px" DataField="GuardCardNumber" FilterControlWidth="72px" ShowFilterIcon="false" SortExpression="GuardCardNumber"></telerik:GridBoundColumn>                    --%>
                    <telerik:GridDateTimeColumn  HeaderText="Guard Card Expired" HeaderStyle-Width="110px" DataField="GuardCardExpired" FilterControlWidth="63px" ShowFilterIcon="false"></telerik:GridDateTimeColumn>
                   <%-- <telerik:GridBoundColumn HeaderText="Fire Arm Number" HeaderStyle-Width="90px" DataField="FireArmNumber" FilterControlWidth="72px" ShowFilterIcon="false" SortExpression="FireArmNumber"></telerik:GridBoundColumn>                   
                    <telerik:GridDateTimeColumn  HeaderText="Fire Arm Expired" HeaderStyle-Width="90px" DataField="FireArmExpired" FilterControlWidth="63px" ShowFilterIcon="false"></telerik:GridDateTimeColumn>--%>
                    <telerik:GridTemplateColumn HeaderText="On Call" HeaderStyle-Width="80px" AllowFiltering="false" UniqueName="OnCallButton">
                    <ItemTemplate>
                      <telerik:RadButton ID="btnOnCall" runat="server" Text="On Call" CommandName="OnCall" >
                          <Icon PrimaryIconCssClass="rbAdd" PrimaryIconLeft="4" PrimaryIconTop="4"></Icon>
                      </telerik:RadButton>
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

***************************************VB CODE*********************
  Protected Sub rgOfficersToCallIn_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgOfficersToCallIn.ItemCommand
        Try
            lblMessage.Text = ""
            divMessage.Visible = False            Dim setDate As Date? = rdtpCallIn.SelectedDate.ToString()
            If setDate Is Nothing Then
                Return
            End If
            Dim cellEmployeeID As TableCell = e.Item.Cells(DirectCast(eOfficersCallInColumns.HREmployeeID, Int32))
            If e.CommandName.ToString() = "OnCall" Then
                Dim dba As New DBAccess
                If dba.InsertCallInOfficer(m_SessionID, Convert.ToInt32(cellEmployeeID.Text), setDate) Then
                    If e.Item.Selected = True Then
                        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
                        Dim btn As RadButton = DirectCast(item("OnCallButton").FindControl("btnOnCall"), RadButton)
                        btn.Enabled = False
                    End If
                    rgCallIn.Rebind()
                    upCallIn.Update()
                    divMessage.Visible = True
                    lblMessage.Text = "Officer is now on call for " + setDate
                Else
                    rgCallIn.DataSource = New String() {}
                    rgCallIn.DataBind()
                End If
            End If


        Catch ex As Exception
        End Try
    End Sub

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Mar 2014, 06:29 AM
Hi Avihai,

Please try the below sample code snippet. I guess you want to disable the button click after one click for selected rows.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowSelection="true">
    <MasterTableView DataKeyNames="ProductID">
        <Columns>
          <telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID"/>          
          <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" UniqueName="ProductName" />
          <telerik:GridTemplateColumn HeaderText="On Call" UniqueName="OnCallButton">
                <ItemTemplate>
                    <telerik:RadButton ID="btnOnCall" runat="server" Text="On Call" CommandName="OnCall">
                        <Icon PrimaryIconCssClass="rbAdd" PrimaryIconLeft="4" PrimaryIconTop="4"></Icon>
                    </telerik:RadButton>
                </ItemTemplate>
          </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="True" />
    </ClientSettings>
</telerik:RadGrid>

VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName.ToString() = "OnCall" Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        If e.Item.Selected = True Then
            Dim btn As RadButton = DirectCast(item.FindControl("btnOnCall"), RadButton)
            btn.Enabled = False
        End If
    End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Avihai
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or