Enable/Disable Command Item

5 posts, 1 answers
  1. Akhil Raj
    Akhil Raj avatar
    69 posts
    Member since:
    Aug 2012

    Posted 07 Jun 2010 Link to this post

    hi ,
      I had rad grid with all operation. In commanditem template i used on link button for add record command. The first column i have name and this is also link button in the itemtemplate. when i click this link reocrd can edit. My design is follows


                <telerik:RadGrid ID="Rad_grd1" runat="server" AutoGenerateColumns="false" GridLines="None" BorderWidth="0" AllowSorting="true"  Width="100%" PageSize="20" AllowPaging="true" PagerStyle-Mode="NextPrev" PagerStyle-AlwaysVisible="true" PagerStyle-HorizontalAlign="Right" > 
                       
                    <ClientSettings> 
                      <Resizing AllowRowResize ="true" /> 
                      <Selecting AllowRowSelect="true" /> 
                      <Scrolling AllowScroll ="true" UseStaticHeaders ="true"  SaveScrollPosition="true"/>                    
                      <ClientEvents OnScroll="HandleScrolling" /> 
                   </ClientSettings> 
     
                       <MasterTableView DataKeyNames="ID, ParameterCollectionTypeId, Status" ClientDataKeyNames="ID" TableLayout="Fixed" CommandItemDisplay="Top" EditMode="EditForms" > 
                           <RowIndicatorColumn Visible="True">  
                           </RowIndicatorColumn> 
                        <Columns> 
                            <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="#">  
                                <ItemTemplate> 
                                    <asp:Label ID="numberLabel" runat="server" Width="30px" /> 
                                </ItemTemplate> 
                                <HeaderStyle Width="30px" /> 
                            </telerik:GridTemplateColumn> 
                            <telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name">  
                                <ItemTemplate> 
                                    <asp:LinkButton ID="lnkbtn_Edit" runat="server" CommandName="Edit" Text='<%#Eval("Name") %>'></asp:LinkButton> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                      </Columns> 
                         <EditFormSettings EditFormType="Template">  
                            <FormTemplate> 
                                <table width="100%">  
                                    <tr> 
                                        <td colspan="2">  
                                            <asp:ValidationSummary ID="vs_Summary1" CssClass="" runat="server" ValidationGroup="EditValidation" ShowSummary="true"    
                                                ForeColor="Red" DisplayMode="BulletList" /> 
     
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            <asp:Label ID="lbl_etHeading" runat="server" Text="Add New Parameter"></asp:Label> 
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td width="15%">  
                                            <asp:Label ID="lbl_etName" runat="server" Text="ParameterName :"></asp:Label> 
                                        </td> 
                                        <td width="85%">  
                                            <telerik:RadTextBox ID="rad_txt_etName" Width="200px" runat="server" Text='<%#Bind("Name") %>' SelectionOnFocus="CaretToEnd"></telerik:RadTextBox> 
                                            <asp:RequiredFieldValidator ID="rfv_etName" Display="Dynamic" ValidationGroup="EditValidation" 
                                                SetFocusOnError="true" runat="server" ControlToValidate="rad_txt_etName" 
                                                ErrorMessage="Name is Mandatory!!!" Text="*" ForeColor="Red"></asp:RequiredFieldValidator> 
                                        </td> 
                                    </tr> 
                              </table> 
                            </FormTemplate> 
                         </EditFormSettings>     
                        
                       <CommandItemTemplate> 
                            <asp:LinkButton ID="lnkbtn_AddNew" runat="server" CommandName="InitInsert" Text="Add New Name"></asp:LinkButton> 
                        </CommandItemTemplate>   
                      </MasterTableView> 
                </telerik:RadGrid> 
     

    My scenario is When one process doing no other opertions are allowed. So when i click "add new name" i disbale the add new button and also the links in name field. In edit command and insert command i need to do this and in update and cancel command i need to enable again.? 

    I tried but i dont know why it not working. but i had one combo box outside the gridview and when i disable that combobox and enable that working nicely. The add new button's text is set in the itemcreated event of grid. i tried in the item command after databind the insert mode, but after disbale again the itemcreated event calling from override skin property?

    Can anyone please give the solution?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Jun 2010 Link to this post

    Hello Akhil,

    I hope the following code snippet will work for you.

    C#:
    protected void Rad_grd1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if ( e.Item.OwnerTableView.IsItemInserted && e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                LinkButton editbutton = (LinkButton)item.FindControl("lnkbtn_Edit"); 
                editbutton.Enabled = false;           
            } 
            if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridCommandItem) 
            { 
                GridCommandItem commandItem = (GridCommandItem)e.Item; 
                LinkButton editbutton = (LinkButton)commandItem.FindControl("lnkbtn_AddNew"); 
                editbutton.Enabled = false
            } 
         } 

    Regards,
    Shinu.


  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Akhil Raj
    Akhil Raj avatar
    69 posts
    Member since:
    Aug 2012

    Posted 08 Jun 2010 Link to this post

    hi shinu ya thats working nice in insert mode.
    But i need in edit mode also. When i click any item grid in edit mode, that time i also need to disbale all other edit links and add new link
  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Jun 2010 Link to this post

    Hello Akhil,

    Make the following changes in the above code and check whether it works for you.
    C#:

     
     protected void Rad_grd1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if ((e.Item.OwnerTableView.IsItemInserted || Rad_grd1.EditIndexes.Count > 0) && e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                LinkButton editbutton = (LinkButton)item.FindControl("lnkbtn_Edit"); 
                editbutton.Enabled = false;           
            } 
            if ((e.Item.OwnerTableView.IsItemInserted || Rad_grd1.EditIndexes.Count > 0) && e.Item is GridCommandItem) 
            { 
                GridCommandItem commandItem = (GridCommandItem)e.Item; 
                LinkButton editbutton = (LinkButton)commandItem.FindControl("lnkbtn_AddNew"); 
                editbutton.Enabled = false
            } 
        } 

    Regards,
    Shinu.
  6. Akhil Raj
    Akhil Raj avatar
    69 posts
    Member since:
    Aug 2012

    Posted 08 Jun 2010 Link to this post

    ya nice idea i thanks friend working nicely
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017