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ü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ügen" CancelText="Abbrechen" UpdateText="Aktualisieren" ></telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ItemStyle-Width="100px" commandname="Delete" text="Lö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!