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

Get a cell value of the row when delete command is fired

2 Answers 515 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 05 Jun 2014, 08:17 PM
Hi,
I have this grid:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" Culture="it-IT" DataSourceID="SqlDataSource1" Skin="Outlook" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateColumns="False" Height="600px" OnItemDataBound="RadGrid1_ItemDataBound" OnDeleteCommand="RadGrid1_DeleteCommand" OnItemCommand="RadGrid1_ItemCommand">
                        <ExportSettings>
                            <Pdf PageWidth="">
                            </Pdf>
                        </ExportSettings>
                        <ClientSettings>
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        </ClientSettings>
                        <MasterTableView CommandItemDisplay="Top" DataKeyNames="Id" DataSourceID="SqlDataSource1">
                            <Columns>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                                    <HeaderStyle Width="30px" />
                                </telerik:GridEditCommandColumn>
                                <telerik:GridTemplateColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" SortExpression="Id" UniqueName="Id">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="IdTextBox" runat="server" Text='<%# Bind("Id") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="Location" FilterControlAltText="Filter Location column" HeaderText="Location" SortExpression="Location" UniqueName="Location" Display="False">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ProjManag" FilterControlAltText="Filter ProjManag column" HeaderText="Proj. Manager" SortExpression="ProjManag" UniqueName="ProjManag">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Pnumber" DataType="System.Int32" FilterControlAltText="Filter Pnumber column" HeaderText="Pnumber" SortExpression="Pnumber" UniqueName="Pnumber">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Country" FilterControlAltText="Filter Country column" HeaderText="Country" SortExpression="Country" UniqueName="Country">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Customer" FilterControlAltText="Filter Customer column" HeaderText="Customer" SortExpression="Customer" UniqueName="Customer">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Type" FilterControlAltText="Filter Type column" HeaderText="Type" SortExpression="Type" UniqueName="Type">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Designation" FilterControlAltText="Filter Designation column" HeaderText="Designation" SortExpression="Designation" UniqueName="Designation">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Status" FilterControlAltText="Filter Status column" HeaderText="Status" SortExpression="Status" UniqueName="Status">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="StatusDate" DataType="System.DateTime" FilterControlAltText="Filter StatusDate column" HeaderText="Status Date" SortExpression="StatusDate" UniqueName="StatusDate" DataFormatString="{0:dd/MM/yyyy}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Probabilities" DataType="System.Int32" FilterControlAltText="Filter Probabilities column" HeaderText="Probabilities [%]" SortExpression="Probabilities" UniqueName="Probabilities">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Budget" FilterControlAltText="Filter Budget column" HeaderText="Budget" SortExpression="Budget" UniqueName="Budget" Display="False">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="NumbVehicles" DataType="System.Int32" FilterControlAltText="Filter NumbVehicles column" HeaderText="Vehicles Q.ty" SortExpression="NumbVehicles" UniqueName="NumbVehicles" DataFormatString="{0:N0}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ContrValue" DataType="System.Int32" FilterControlAltText="Filter ContrValue column" HeaderText="Value [CHF]" SortExpression="ContrValue" UniqueName="ContrValue" DataFormatString="{0:N0}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EngHours" DataType="System.Int32" FilterControlAltText="Filter EngHours column" HeaderText="Eng. Hours" SortExpression="EngHours" UniqueName="EngHours" Display="False" DataFormatString="{0:N0}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ExpOrderDate" DataType="System.DateTime" FilterControlAltText="Filter ExpOrderDate column" HeaderText="Order Date" SortExpression="ExpOrderDate" UniqueName="ExpOrderDate" DataFormatString="{0:MM/yyyy}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="FirstDelivery" DataType="System.DateTime" FilterControlAltText="Filter FirstDelivery column" HeaderText="First Delivery" SortExpression="FirstDelivery" UniqueName="FirstDelivery" Display="False" DataFormatString="{0:MM/yyyy}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="LastDelivery" DataType="System.DateTime" FilterControlAltText="Filter LastDelivery column" HeaderText="Last Delivery" SortExpression="LastDelivery" UniqueName="LastDelivery" Display="False" DataFormatString="{0:MM/yyyy}">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Agent" FilterControlAltText="Filter Agent column" HeaderText="Agent" SortExpression="Agent" UniqueName="Agent" Display="False">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Notes" FilterControlAltText="Filter Notes column" HeaderText="Review 1" SortExpression="Notes" UniqueName="Notes" Display="False">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Notes2" Display="False" FilterControlAltText="Filter Notes2 column" HeaderText="Review 2" SortExpression="Notes2" UniqueName="Notes2">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Notes3" Display="False" FilterControlAltText="Filter Notes3 column" HeaderText="Review 3" SortExpression="Notes3" UniqueName="Notes3">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="user" FilterControlAltText="Filter user column" HeaderText="user" UniqueName="user" Visible="False">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="insertDate" Display="False" FilterControlAltText="Filter insertDate column" HeaderText="insertDate" UniqueName="insertDate">
                                    <ColumnValidationSettings>
                                        <ModelErrorMessage Text="" />
                                    </ColumnValidationSettings>
                                </telerik:GridBoundColumn>
                                <telerik:GridButtonColumn ButtonType="ImageButton" Text="Delete" CommandName="Delete" FilterControlAltText="Filter column1 column" ConfirmDialogType="RadWindow" ConfirmText="Do you really want to delete this project and all its content?" UniqueName="column1">
                                    <HeaderStyle Width="30px" />
                                </telerik:GridButtonColumn>
                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
                                <FormTemplate>
                                    <style type="text/css">
                                        .auto-style1 {
                                            width: 100%;
                                            background-color: azure;
                                        }
 
                                        .auto-style2 {
                                            width: 124px;
                                        }
 
                                        .auto-style4 {
                                            width: 163px;
                                        }
 
                                        .auto-style5 {
                                            text-align: left;
                                            width: 386px;
                                        }
 
                                        .auto-style6 {
                                            height: 12px;
                                        }
 
                                        .auto-style7 {
                                            font-size: xx-small;
                                        }
                                    </style>
 
                                    <table class="auto-style1">
                                        <tr>
                                            <td class="auto-style2">Record ID:</td>
                                            <td class="auto-style5">
                                                <asp:Label ID="RecordID" ReadOnly="true" runat="server" Text='<%# Bind( "Id" ) %>'>></asp:Label>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Location:</td>
                                            <td class="auto-style5">
                                                <asp:DropDownList ID="Location" runat="server" Width="200px" Height="22px" SelectedValue='<%# Bind("Location") %>'
                                                    DataSource='<%# (new string[] { "STAMI", "BKM", "STAPS", "STAG", "STAWI", "SPATZ"}) %>'
                                                    AppendDataBoundItems="True">
                                                    <asp:ListItem Selected="True">
                                                    </asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="Location" ErrorMessage="Select a location" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Probabilities [%]:</td>
                                            <td>
                                                <asp:TextBox ID="Probabilities" runat="server" Width="200px" Height="22px" Text='<%# Bind( "Probabilities" ) %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="Probabilities" ErrorMessage="This field shall be filled" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="Probabilities"
                                                    ErrorMessage="Enter Value between 0 to 100" ForeColor="Red" MaximumValue="100"
                                                    MinimumValue="0" Type="Integer" SetFocusOnError="True">
                                                </asp:RangeValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Project Manager:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="ProjManag" runat="server" Width="200px" Height="22px" Text='<%# Bind( "ProjManag" ) %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="ProjManag" ErrorMessage="This field shall be filled" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="ProjManag"
                                                    ValidationExpression="^([\S\s]{0,25})$"
                                                    ErrorMessage="Please enter maximum 25 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Budget:</td>
                                            <td>
                                                <asp:DropDownList ID="Budget" runat="server" Height="22px" Width="200px" SelectedValue='<%# Bind("Budget") %>'
                                                    DataSource='<%# (new string[] { "Yes", "Not"}) %>'
                                                    AppendDataBoundItems="True">
                                                    <asp:ListItem Selected="True">
                                                    </asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="Budget" ErrorMessage="Select if in budget or not" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Pnumber:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Pnumber" runat="server" Width="200px" Height="22px" Text='<%# Bind( "Pnumber" ) %>'>></asp:TextBox>
                                                <asp:CompareValidator ID="cv" runat="server" ControlToValidate="Pnumber" Type="Integer" Operator="DataTypeCheck" BackColor="Red" ErrorMessage="Value must be anumber!" />
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Pnumber"
                                                    ValidationExpression="^([\S\s]{0,4})$"
                                                    ErrorMessage="Please enter maximum 4 numbers" BackColor="red">
                                                </asp:RegularExpressionValidator>
 
 
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Quantity of vehicles:</td>
                                            <td>
                                                <asp:TextBox ID="Quantity" runat="server" Width="200px" Height="22px" Text='<%# Bind( "NumbVehicles") %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="Quantity" ErrorMessage="This field shall be filled" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator3"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Quantity"
                                                    ValidationExpression="^([\S\s]{0,4})$"
                                                    ErrorMessage="Please enter maximum 4 digit number" BackColor="red">
                                                </asp:RegularExpressionValidator>
 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Country:</td>
                                            <td class="auto-style5">
                                                <asp:DropDownList ID="Country" runat="server" Height="22px" Width="200px" SelectedValue='<%# Bind("Country") %>'
                                                    DataSource='<%# (new string[]{ "Belarus", "Russian Federation","Armenia", "Estonia", "Georgia", "Kazakhstan", "Latvia",
                                                "Lithuania",  "Afghanistan",
                                                "Albania", "Algeria", "Andorra", "Angola", "Argentina", "Australia", "Austria", "Azerbaijan", "Bahrain",
                                                "Bangladesh", "Belgium", "Bolivia", "Bosnia and Herzegovina",
                                                "Botswana", "Brazil", "Bulgaria", "Cambodia", "Cameroon", "Canada", "Chile", "China", "Colombia", "Congo",
                                                "Congo DR", "Costa Rica", "Cote Ivoire", "Croatia", "Cuba",
                                                "Cyprus", "Czech Rep", "Denmark", "Dominican Rep", "Ecuador", "Egypt", "Eritrea", "Ethiopia",
                                                "Germany", "Ghana", "Greece", "Guatemala", "Honduras", "Hong Kong",
                                                "Hungary", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Japan", "Jordan",
                                                "Kenya", "Korea N", "Korea S", "Kuwait", "Kyrgyzstan", "Lebanon", "Liechtenstein", "Luxembourg",
                                                "Macedonia", "Madagascar", "Malawi", "Malaysia", "Malta", "Mexico", "Moldova", "Monaco",
                                                "Mongolia", "Morocco", "Mozambique", "Myanmar", "Namibia", "Netherlands", "New Zealand", "Nicaragua",
                                                "Nigeria", "Norway", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
                                                "Qatar", "Romania", "Rwanda", "Saudi Arabia", "Senegal", "Serbia", "Slovakia", "Slovenia",
                                                "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Sweden", "Switzerland", "Syria", "Taiwan",
                                                "Tajikistan", "Tanzania", "Thailand", "Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine",
                                                "UAE", "UK", "USA", "Uruguay", "Uzbekistan", "Venezuela",
                                                "Viet Nam", "Yemen", "Zambia", "Zimbabwe" }) %>'
                                                    AppendDataBoundItems="True">
                                                    <asp:ListItem Selected="True">
                                                    </asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="Country" ErrorMessage="Select a country" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Approx. contract value:</td>
                                            <td>
                                                <asp:TextBox ID="ContractValue" runat="server" Width="200px" Height="22px" Text='<%# Bind( "ContrValue") %>'>></asp:TextBox>
                                                <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="ContractValue" Type="Integer" Operator="DataTypeCheck" BackColor="Red" ErrorMessage="Value must be anumber!" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" ControlToValidate="ContractValue" ErrorMessage="Type the contract value" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RangeValidator ID="RangeValidator3" runat="server"
                                                    ControlToValidate="ContractValue" ErrorMessage="Maximum value is 500.000.000"
                                                    MaximumValue="500000000" MinimumValue="0"></asp:RangeValidator>
 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Customer:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Customer" runat="server" Width="200px" Height="22px" Text='<%# Bind( "Customer" ) %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" ControlToValidate="Customer" ErrorMessage="Type the customer name" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator5"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Customer"
                                                    ValidationExpression="^([\S\s]{0,36})$"
                                                    ErrorMessage="Please enter maxium 36 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
 
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Engineering hours:</td>
                                            <td>
                                                <asp:TextBox ID="EngHours" runat="server" Width="200px" Height="22px" Text='<%# Bind( "EngHours") %>'>></asp:TextBox>
                                                <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="EngHours" Type="Integer" Operator="DataTypeCheck" BackColor="Red" ErrorMessage="Value must be anumber!" />
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator6"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="EngHours"
                                                    ValidationExpression="^([\S\s]{0,6})$"
                                                    ErrorMessage="Please enter maxium 6 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Vehicle Type:</td>
                                            <td class="auto-style5">
                                                <asp:DropDownList ID="VehicleType" runat="server" Width="200px" Height="22px" SelectedValue='<%# Bind("Type") %>'
                                                    DataSource='<%# (new string[] { "TB", "Tram", "Hybrid", "Train", "Sub-systems", "Spare parts", "Services"}) %>'
                                                    AppendDataBoundItems="True">
                                                    <asp:ListItem Selected="True">
                                                    </asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="VehicleType" ErrorMessage="Select a location" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Expected order date:</td>
                                            <td>
                                                <telerik:RadDatePicker ID="OrderDate" runat="server" MinDate="1/1/2010" DbSelectedDate='<%# Bind("ExpOrderDate") %>'>
                                                </telerik:RadDatePicker>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator14" ControlToValidate="OrderDate" ErrorMessage="An approximate order date shall be selected" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Designation:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Designation" runat="server" Width="200px" Height="22px" Text='<%# Bind( "Designation" ) %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator10" ControlToValidate="Designation" ErrorMessage="Select a vehicle designation" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator7"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Designation"
                                                    ValidationExpression="^([\S\s]{0,25})$"
                                                    ErrorMessage="Please enter maxium 14 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">First delivery:</td>
                                            <td>
                                                <telerik:RadDatePicker ID="FirstDelivery" runat="server" MinDate="1/1/2010" DbSelectedDate='<%# Bind("FirstDelivery") %>'>
                                                </telerik:RadDatePicker>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Status:</td>
                                            <td class="auto-style5">
                                                <asp:DropDownList ID="Status" runat="server" Height="22px" Width="200px" SelectedValue='<%# Bind("Status") %>'
                                                    DataSource='<%# (new string[] { "I", "R", "A", "P", "O", "L", "B", "X", "Y", "Z"}) %>'
                                                    AppendDataBoundItems="True">
                                                    <asp:ListItem Selected="True">
                                                    </asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator15" ControlToValidate="Status" ErrorMessage="Select a status" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Last delivery:</td>
                                            <td>
                                                <telerik:RadDatePicker ID="LastDelivery" runat="server" MinDate="1/1/2010" DbSelectedDate='<%# Bind("LastDelivery") %>'>
                                                </telerik:RadDatePicker>
 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Stadus date:</td>
                                            <td class="auto-style5">
                                                <telerik:RadDatePicker ID="StatusDate" runat="server" MinDate="1/1/2010" DbSelectedDate='<%# Bind("StatusDate") %>'>
                                                </telerik:RadDatePicker>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator13" ControlToValidate="StatusDate" ErrorMessage="Select a status date" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4">Agent:</td>
                                            <td>
                                                <asp:TextBox ID="Agent" runat="server" Width="200px" Height="22px" Text='<%# Bind( "Agent" ) %>'>></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator12" ControlToValidate="Agent" ErrorMessage="If there is no agent insert -Not-" runat="server" BackColor="Red">
                                                </asp:RequiredFieldValidator>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator8"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Agent"
                                                    ValidationExpression="^([\S\s]{0,22})$"
                                                    ErrorMessage="Please enter maxium 22 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2"> </td>
                                            <td class="auto-style5"> </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Review 1:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Notes1" runat="server" Height="125px" TextMode="MultiLine" Width="370px" Text='<%# Bind( "Notes" ) %>'></asp:TextBox>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator9"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Notes1"
                                                    ValidationExpression="^([\S\s]{0,150})$"
                                                    ErrorMessage="Please enter maxium 150 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td>
                                                <table class="auto-style6">
                                                    <tr>
                                                        <td style="font-size: xx-small"><strong>I</strong> = Project identified</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>R</strong> = Given target price</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>A</strong> = Tender documents received</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>P</strong> = Prequalification set out</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>O</strong> = Offer set out</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>O</strong> = Offer set out & tender accepted (90%)</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>L</strong> = LOI received (99%)</td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>B</strong> = Ordered (100%) </td>
                                                    </tr>
                                                    <tr>
                                                        <td class="auto-style7"><strong>X</strong> = Cancelled / <strong>Y</strong> = Postponed / <strong>Z</strong> = Lost</td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2"> </td>
                                            <td class="auto-style5"> </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Review 2:</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Notes2" runat="server" Height="125px" TextMode="MultiLine" Width="370px" Text='<%# Bind( "Notes2" ) %>'></asp:TextBox>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator11"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Notes2"
                                                    ValidationExpression="^([\S\s]{0,150})$"
                                                    ErrorMessage="Please enter maxium 150 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td>
                                                <asp:Label ID="Label2" runat="server" Text="Added by: "></asp:Label>
                                                <asp:Label ID="user" ReadOnly="true" runat="server" Text='<%# Bind( "user" ) %>'>></asp:Label>
                                                <br />
                                                <asp:Label ID="Label3" runat="server" Text="Added on: "></asp:Label>
                                                <asp:Label ID="insertDate" ReadOnly="true" runat="server" Text='<%# Bind( "insertDate", "{0:dd/MM/yyyy}" ) %>'>></asp:Label>
 
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2"> </td>
                                            <td class="auto-style5"> </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2">Review 3::</td>
                                            <td class="auto-style5">
                                                <asp:TextBox ID="Notes3" runat="server" Height="125px" TextMode="MultiLine" Width="370px" Text='<%# Bind( "Notes3" ) %>'></asp:TextBox>
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator12"
                                                    runat="server" Display="dynamic"
                                                    ControlToValidate="Notes3"
                                                    ValidationExpression="^([\S\s]{0,150})$"
                                                    ErrorMessage="Please enter maxium 150 characters" BackColor="red">
                                                </asp:RegularExpressionValidator>
                                            </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2"></td>
                                            <td class="auto-style5"></td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td>
                                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>
                                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                    CommandName="Cancel" Style="text-align: right"></asp:Button>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="auto-style2"> </td>
                                            <td class="auto-style5"> </td>
                                            <td> </td>
                                            <td class="auto-style4"> </td>
                                            <td> </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                            </EditFormSettings>
                            <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                        </MasterTableView>
                    </telerik:RadGrid>

and I need to get the cell value of the "Id" column when the delete command is pressed.

protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
   {
       //record delete record
       GridDataItem item = (GridDataItem)e.Item;
       string cname = item["Id"].Text;
       Utilities.Record_Transaction("Projects:Delete -" + cname, (string)Session["userName"]);
   }

Could some one please help? I cannot get the value of the  "Id" cell of the deleted record in the string "cname". 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jun 2014, 04:15 AM
Hi Felice,

In your code you have set the Id in a Template column and you are trying to access it in OnDeleteCommand directly which is not possible. Please try the following code snippet:

C#:
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
    GridDataItem dataItem = (GridDataItem)e.Item;
    //Using DataKeyValue to access the Id
    string cname = dataItem.GetDataKeyValue("Id").ToString();
                     //OR
    //Accessing the TemplateColumn Label and get Id
    Label lblId = (Label)dataItem.FindControl("IdLabel");
    string cname = lblId.Text;
}

Thanks,
Shinu
0
Felice
Top achievements
Rank 1
answered on 06 Jun 2014, 04:27 AM
Dear Shinu,
thanks a lot. It works fine and you are very helpful as usual. 

Kind regards
Felice
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Felice
Top achievements
Rank 1
Share this question
or