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

DeleteCommand Get Values

1 Answer 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
July
Top achievements
Rank 2
July asked on 23 May 2012, 03:36 PM

How I can get "Name" Column value on DeleteCommand,

aspx:
<telerik:RadGrid ID="SecurityGrid" runat="server" OnNeedDataSource="SecurityGrid_NeedDataSource"
            OnItemCommand="SecurityGrid_ItemCommand" OnPreRender="SecurityGrid_PreRender"
            OnDeleteCommand="UserGrid_DeleteCommand" OnUpdateCommand="SecurityGrid_UpdateCommand"
            OnInsertCommand="SecurityGrid_InsertCommand" AutoGenerateColumns="False" OnItemCreated="SecurityGrid_ItemCreated">
            <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top" EditMode="InPlace" TableLayout="Auto"
                Width="100%">
                <Columns>
                    <telerik:GridEditCommandColumn HeaderStyle-Width="2%" UniqueName="EditCommandColumn"
                        ButtonType="ImageButton" EditImageUrl="../Images/grid_edit.png">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn UniqueName="btnDelete" ConfirmDialogType="RadWindow" ButtonType="ImageButton"
                        CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="300px" HeaderStyle-Width="2%" />
                    <telerik:GridTemplateColumn DataField="Id" UniqueName="Id" Visible="false">
                        <InsertItemTemplate>
                            <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Id") %>' ReadOnly="true"
                                Enabled="false" />
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Eval("Id") %>' ReadOnly="true" />
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="Name" DataField="Name">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtName" Width="120px" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RFName" runat="server" ErrorMessage="*" CssClass="validator"
                                ControlToValidate="txtName"></asp:RequiredFieldValidator>
                            <asp:CustomValidator ID="cvName" CssClass="validator" OnServerValidate="cvName_ServerValidate"
                                Display="Dynamic" runat="server" ControlToValidate="txtName"></asp:CustomValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="Level" DataField="Level">
                        <EditItemTemplate>
                            <telerik:RadNumericTextBox ID="txtLevel" Width="50px" runat="server" DbValue='<%# DataBinder.Eval(Container.DataItem, "Level") %>'>
                                <NumberFormat DecimalDigits="0" />
                            </telerik:RadNumericTextBox>
                            <asp:RequiredFieldValidator ID="RFLevel" runat="server" ErrorMessage="*" CssClass="validator"
                                ControlToValidate="txtLevel"></asp:RequiredFieldValidator>
                            <asp:CustomValidator ID="cvLevel" CssClass="validator" OnServerValidate="cvLevel_ServerValidate"
                                Display="Dynamic" runat="server" ControlToValidate="txtLevel"></asp:CustomValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblLevel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Level") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <CommandItemTemplate>
                    <div style="width: 100%">
                        <div style="width: 10%; margin-left: 12px; float: left">
                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert">
                                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/UI/Images/add.png" />
                                <asp:Label ID="lblQuickAdd" runat="server" /></asp:LinkButton>&nbsp;&nbsp;
                        </div>
                    </div>
                </CommandItemTemplate>
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnColumnHidden="onColumnHidden" OnRowDblClick="RowDblClick" />
            </ClientSettings>
        </telerik:RadGrid>


.cs


  protected void UserGrid_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            string securityLevelId = ((GridDataItem) e.Item).GetDataKeyValue("Id").ToString();
            Session["ID"] = securityLevelId;

            bool hasUser = Master.Organization.SecurityLevelHasUser(Convert.ToInt16(securityLevelId));
            bool hasDocument = Master.Organization.SecurityLevelHasDocument(Convert.ToInt16(securityLevelId));

            LogConfig.SaveInFile(Level.Debug, "Show Deleted popup", null, typeof (SecurityLevel).FullName,
                                 Master.StackTrace.GetFrame(1).GetMethod().Name);


            GridDataItem dataItem = e.Item as GridDataItem;
            string contactName = dataItem["Name"].Text;-->
THIS IS NULL
          

        
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 May 2012, 06:04 AM
Hello,

I suppose you want to access the Label placed in the template column. Here is the sample code.
C#:
void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
GridDataItem dataItem = e.Item as GridDataItem;
Label lbl = (Label)dataItem.FindControl("lblName");
string value = lbl.Text;
}

Thanks,
Shinu.
Tags
Grid
Asked by
July
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or