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

RadGrid - Unable to get insert values From Edit Form with Multiple Columns

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hunter
Top achievements
Rank 1
Hunter asked on 17 Apr 2013, 04:36 PM
I am trying to get values when inserting from an Edit Form (with Multiple Columns) in preparation for writing a record to the database.  I'm sure it's something simple t o get this working.  However when I try to retrieve the value for a field in the InsertCommand handler it looks like the textbox can't be located.  I'm not sure what I should cast e.item to in the handler.  I've seen and tried three different types unsuccessfully: GridEditFormInsertItem, GridEditFormItem and GridEditableItem. 

<telerik:RadGrid ID="rgLocations" runat="server" Width="100%"  AutoGenerateColumns="false"
        Skin="Office2010Black"  ItemStyle-BackColor="#ffe394" BorderColor="White"
        ShowFooter="false"  OnNeedDataSource="rgLocations_NeedDataSource" OnInsertCommand="rgLocations_InsertCommand">
        <AlternatingItemStyle BackColor="White" />
        <FooterStyle BackColor="#cccccc" />
        <HeaderStyle ForeColor="White" />
        <PagerStyle AlwaysVisible="true" Position="TopAndBottom" ForeColor="White"   />
         <MasterTableView  CommandItemDisplay="Top" DataKeyNames="ClientLocationID" >
            <Columns>
                <telerik:GridBoundColumn DataField="ClientLocationID" Visible="false"  ReadOnly="true"/>
                <telerik:GridTemplateColumn HeaderText="Edit">
                    <ItemTemplate>
                        <asp:ImageButton ID="ibtnEdit" ImageUrl="~/images/silk/pencil_go.png" CommandName="Edit"
                            runat="server" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="ClientID" HeaderText="Client" Visible="false"  ReadOnly="true" />
                <telerik:GridBoundColumn DataField="LocationName" HeaderText="Location" EditFormColumnIndex="0" />
                <telerik:GridBoundColumn DataField="PublicIPs" HeaderText="Public IPs" EditFormColumnIndex="0"/>
                <telerik:GridBoundColumn DataField="PrivateIPs" HeaderText="Private IPs"  EditFormColumnIndex="0" />
                <telerik:GridBoundColumn DataField="Address1" HeaderText="Address1" EditFormColumnIndex="1" />
                <telerik:GridBoundColumn DataField="Address2" HeaderText="Address2" EditFormColumnIndex="1" />
                <telerik:GridBoundColumn DataField="City" HeaderText="City" EditFormColumnIndex="2" />
                <telerik:GridBoundColumn DataField="State" HeaderText="State" EditFormColumnIndex="2" />
                <telerik:GridBoundColumn DataField="Zip" HeaderText="Zip"  EditFormColumnIndex="2" />
                
                <telerik:GridTemplateColumn  ReadOnly="true" HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <asp:ImageButton ID="ibtnDelete" CommandName="Delete" runat="server" ImageUrl="images/1263447248_cross.png" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <EditFormSettings ColumnNumber="3" CaptionFormatString="Edit details for Notification {0}" CaptionDataField="LocationName">
                <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="5" Width="200" />
                <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="5" CssClass="module"  Height="110px" Width="100%"></FormTableStyle>
                <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>




Protected Sub rgLocations_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
    Dim ClientID As String = Session("ClientID")
    Dim oCLientLocations As clsClientLocations = New clsClientLocations(ClientID)
    rgLocations.DataSource = oCLientLocations.DataTable
End Sub
 
Protected Sub rgLocations_InsertCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs)
    Dim editedItem As GridEditFormItem = CType(e.Item, GridEditableItem)
     
    Dim LocationName As String = CType(editedItem("LocationName").FindControl(0), TextBox).Text
End Sub
 
In the ItemCOmmand handler, the LocationName does not get set.  I the error message: "Object reference not set to an instance of an object."  WHich is because editItem("LocationName").FindControl(0) is "Nothing".

Thanks in advance for any help on this.

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Apr 2013, 05:34 PM
Hello,

Protected Sub RadGrid1_InsertCommand(sender As Object, e As GridCommandEventArgs)
    Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
    Dim str1 As String = TryCast(item("LocationName").Controls(0), TextBox).Text
End Sub

<telerik:GridBoundColumn DataField="LocationName" UniqueName="LocationName" HeaderText="LocationName">
                  </telerik:GridBoundColumn>


Thanks,
Jayesh Goyani
0
Hunter
Top achievements
Rank 1
answered on 18 Apr 2013, 04:40 AM
That did it.  Thanks!
Tags
Grid
Asked by
Hunter
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Hunter
Top achievements
Rank 1
Share this question
or