This is a migrated thread and some comments may be shown as answers.
Can´t get values when insertCommand is fired
4 Answers 123 Views
This is a migrated thread and some comments may be shown as answers.
Ralf Markus
Top achievements
Rank 1
Ralf Markus asked on 15 Feb 2010, 02:17 PM
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!

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 16 Feb 2010, 08:59 AM
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

0
Ralf Markus
Top achievements
Rank 1
answered on 16 Feb 2010, 09:31 AM
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.

0
Ralf Markus
Top achievements
Rank 1
answered on 16 Feb 2010, 10:50 AM
The problem was that I Databind() on every postback so the insert item got initialized all over again.

Thanks!
0
hamid
Top achievements
Rank 1
answered on 11 Dec 2014, 10:51 PM
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();
}
Tags
Grid
Asked by
Ralf Markus
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Ralf Markus
Top achievements
Rank 1
hamid
Top achievements
Rank 1
Share this question
or