Can´t get values when insertCommand is fired

5 posts, 1 answers
  1. Ralf Markus
    Ralf Markus avatar
    8 posts
    Member since:
    Mar 2009

    Posted 15 Feb 2010 Link to this post

    Hi all,

    I have a grid with editMode inPlace. When the user adds a new row and clicks "insert" then I can not manage to get the entered values.

    Would you please help me with this? What am I missing?!

    ASCX code:

    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" MasterTableView-EditMode="InPlace"   
        AutoGenerateColumns="False" Height="150px" oninsertcommand="RadGrid1_InsertCommand" >
    <MasterTableView CommandItemDisplay="Top" InsertItemDisplay="Bottom" ShowHeadersWhenNoRecords="true" >
    <CommandItemTemplate>
    <telerik:RadToolBar ID="rdtbTravelTimeRecording" Runat="server" style="display: block; float: none;
        width: 100%" OnButtonClick="rdtbTravelTimeRecording_ButtonClick"  OnClientButtonClicking="onClientButtonClicking">
        <items>
            <telerik:RadToolBarButton runat="server" Text="Speichern" CommandName="Save" ImageUrl="../../images/icons/Save.png" Width="120px" meta:resourcekey="RadToolBarButtonResource1">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" Text="Zur Genehmigung" CommandName="Approval" ImageUrl="../../images/icons/Clipboard Check.png" Width="120px" meta:resourcekey="RadToolBarButtonResource1">
            </telerik:RadToolBarButton>
            <telerik:RadToolBarButton runat="server" Text="Zeile hinzuf&uuml;gen" CommandName="InitInsert" ImageUrl="../../images/icons/SymbolAdd.png" Width="120px" meta:resourcekey="RadToolBarButtonResource2">
            </telerik:RadToolBarButton>
        </items>
    </telerik:RadToolBar>

    </CommandItemTemplate>
        <Columns>
        <telerik:GridTemplateColumn  HeaderText="Datum" uniquename="column4">
            <ItemTemplate>
                <asp:Label ID="typeText" Text='<%# Eval("Date") %>' runat="server" ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadDatePicker DataField="Date" PickerType="DatePicker" ID="Date" Runat="server"></telerik:RadDatePicker>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn  HeaderText="Von" uniquename="column4">
            <ItemTemplate>
                <asp:Label ID="typeText" Text='<%# Eval("BeginTime") %>' runat="server" ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadTimePicker DataField="BeginTime" PickerType="TimePicker" ID="PickerFrom" Runat="server"></telerik:RadTimePicker>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn  HeaderText="Bis" uniquename="column4">
            <ItemTemplate>
                <asp:Label ID="typeText" Text='<%# Eval("EndTime") %>' runat="server" ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadTimePicker  DataField="EndTime" PickerType="TimePicker" ID="PickerTo" Runat="server"></telerik:RadTimePicker>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn  HeaderText="Anwesenheitsart" uniquename="column4">
            <ItemTemplate>
                <asp:Label ID="typeText" Text="Test" runat="server" ></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <telerik:RadComboBox ID="rdcbReason" Runat="server"></telerik:RadComboBox>
            </EditItemTemplate>
        </telerik:GridTemplateColumn>
        
        <telerik:GridTemplateColumn HeaderText="Reiseort/Reisegrund" uniquename="TemplateColumn">
        
            <ItemTemplate>
                <asp:Label ID="typeText" Text='<%# Eval("Type") %>' runat="server" ></asp:Label>
            </ItemTemplate>
            
            <EditItemTemplate>
                <telerik:RadTextBox Width="250px" ID="TextBox1" Runat="server"></telerik:RadTextBox>
            </EditItemTemplate>
        
        </telerik:GridTemplateColumn>
        
        <telerik:GridEditCommandColumn ItemStyle-Width="100px" UniqueName="EditColumn" EditText="Bearbeiten" InsertText="Einf&uuml;gen" CancelText="Abbrechen" UpdateText="Aktualisieren" ></telerik:GridEditCommandColumn>
        <telerik:GridButtonColumn ItemStyle-Width="100px" commandname="Delete" text="L&ouml;schen" uniquename="DeleteColumn"></telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
    </telerik:RadGrid>

    //Here is what I tried in code behind:
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
            {
                GridDataInsertItem ii;
                ii = (GridDataInsertItem)RadGrid1.MasterTableView.GetInsertItem();
                
                RadDatePicker date;
                RadDateTimePicker rdtpFrom;
                RadDateTimePicker rdtpTo;
                RadComboBox rdcbReason;

                date = (RadDatePicker)ii.FindControl("Date");
                rdtpFrom = (RadDateTimePicker)ii.FindControl("PickerFrom");
                rdtpTo = (RadDateTimePicker)ii.FindControl("PickerTo");
                rdcbReason = (RadComboBox)ii.FindControl("rdcbReason"); 

                DataRow dr = dt2.NewRow();
                dr["Date"] = date.SelectedDate.ToString();
                dr["BeginTime"] = rdtpFrom.TimeView.StartTime.ToString();
                dr["EndTime"] = rdtpFrom.TimeView.EndTime.ToString();
                dr["Type"] = rdcbReason.Text;
                dt2.Rows.Add(dr);

                RadGrid1.DataSource = dt2;
                RadGrid1.DataBind();
            }


    //Thank you very much!
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2010 Link to this post

    Hi,

    Try the code snippet below to access the values in the InsertCommand.You can access using the ColumnUniqueName and the FindControl method. You can use the

    C#
     protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
            { 
                
                GridDataInsertItem ii; 
                ii = (GridDataInsertItem)RadGrid1.MasterTableView.GetInsertItem(); 
                RadDatePicker date = (RadDatePicker)ii["column4"].FindControl("RadDatePicker1"); 
            } 
            

    A  suggestion would be to use the AdvancedDataBinding   technique. You can also  use the ExtractValuesFromItem  which you can refer to from the link below.

    Inserting values in-place and EditForms

    Thanks,
    Princy

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ralf Markus
    Ralf Markus avatar
    8 posts
    Member since:
    Mar 2009

    Posted 16 Feb 2010 Link to this post

    Hello Princy!

    I do get the controls but the value of them is empty or null.

    You can test this by using your own code. Otherwise please attach your working solution so I can figure out why this doesn´t function on my side.

    Thanks again!

    I tried the ExtractValues approach but I also do not get the entered values.

  5. Ralf Markus
    Ralf Markus avatar
    8 posts
    Member since:
    Mar 2009

    Posted 16 Feb 2010 Link to this post

    The problem was that I Databind() on every postback so the insert item got initialized all over again.

    Thanks!
  6. hamid
    hamid avatar
    1 posts
    Member since:
    Dec 2014

    Posted 11 Dec 2014 Link to this post

    you can use this code:
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
    Telerik.Web.UI.GridBatchEditingEventArgument aaa = e.CommandArgument as Telerik.Web.UI.GridBatchEditingEventArgument;
    var val= aaa.NewValues;
    string mystr= val["column_name"].ToString();
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017