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

Enable/Disable Command Item

4 Answers 602 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Akhil Raj
Top achievements
Rank 1
Akhil Raj asked on 07 Jun 2010, 09:10 AM
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?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jun 2010, 11:41 AM
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.


0
Akhil Raj
Top achievements
Rank 1
answered on 08 Jun 2010, 06:29 AM
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
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Jun 2010, 10:41 AM
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.
0
Akhil Raj
Top achievements
Rank 1
answered on 08 Jun 2010, 12:25 PM
ya nice idea i thanks friend working nicely
Tags
Grid
Asked by
Akhil Raj
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Akhil Raj
Top achievements
Rank 1
Share this question
or