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

Access edit items

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Atlas
Top achievements
Rank 1
Atlas asked on 21 May 2011, 01:12 AM
I have the following grid:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="true" Width="100%" GridLines="None"
    PageSize="25" AllowPaging="True" AutoGenerateColumns="False" AllowAutomaticDeletes="True"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
    OnDeleteCommand="RadGrid1_DeleteCommand">
    <PagerStyle Mode="NextPrevAndNumeric" />
    <MasterTableView Width="100%" CommandItemDisplay="Top"
        HorizontalAlign="NotSet" AutoGenerateColumns="False">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" />                                                    
            <telerik:GridBoundColumn DataField="Id" UniqueName="Id" SortExpression="Id"
                HeaderText="Id" ReadOnly="true" />
            <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName"
                SortExpression="FirstName" HeaderText="First Name" MaxLength="128" />
            <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName"
                SortExpression="LastName" HeaderText="Last Name" MaxLength="128" />
            <telerik:GridBoundColumn DataField="Email" UniqueName="Email"
                SortExpression="Email" HeaderText="Email" MaxLength="128" />
            <telerik:GridBoundColumn DataField="CreateDate" UniqueName="CreateDate"
                SortExpression="CreateDate" HeaderText="Create Date"
                DataFormatString="{0:d}" ReadOnly="true" />
            <telerik:GridCheckBoxColumn DataField="IsApproved" UniqueName="IsApproved"
                SortExpression="IsApproved" HeaderText="Is Approved" />
            <telerik:GridCheckBoxColumn DataField="IsComplete" UniqueName="IsComplete"
                SortExpression="IsComplete" HeaderText="Is Complete" />
            <telerik:GridCheckBoxColumn DataField="IsProcessed" UniqueName="IsProcessed"
                SortExpression="IsProcessed" HeaderText="Is Processed" />
            <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ConfirmText="Are you sure you want to delete this application?" ItemStyle-CssClass="cursor" ButtonType="ImageButton" />
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

and I am trying to access the values to perform an update after the user selects update. What gets created in edit mode for the columns above, and how do I access them?

I tried the following, but the items are null:

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
    var item = (GridEditFormItem)e.Item;
    var firstName = e.Item.FindControl("TextBox1") as TextBox;
    var lastName = e.Item.FindControl("TextBox2") as TextBox;
    var email = e.Item.FindControl("TextBox3") as TextBox;
    var isApproved = e.Item.FindControl("CheckBox1") as CheckBox;
    var IsComplete = e.Item.FindControl("CheckBox2") as CheckBox;
    var IsProcessed = e.Item.FindControl("CheckBox3") as CheckBox;


2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 May 2011, 08:41 AM
Hi Nano sacay,

Grid / Accessing Cells and Rows

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx


GridEditableItem editedItem = e.Item as GridEditableItem;
string strName = (editedItem["ColumnUniqueName"].Controls[0] as RadTextBox).Text;
OR
string strName = (editedItem["ColumnUniqueName"].Controls[1] as RadTextBox).Text;
 


Thanks,
Jayesh Goyani
0
Atlas
Top achievements
Rank 1
answered on 23 May 2011, 05:32 PM
Great, thanks for the info. There was one error in the code though. The TextBox is a regular asp.net TextBox, not a RadTextBox.
Tags
Grid
Asked by
Atlas
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Atlas
Top achievements
Rank 1
Share this question
or