I am trying to us a FormTemplate using Pop-up to add/update records.
I get the Call to the Server but when i try to pull values from the Textbox they are coming back as Null that it cant find thought controls. I have search for hours on the forum and tried various thing and just cat seem to get it to work here is the Code.
NOTE: server side i get these 2 error for (THIS IS ON AN INSERT)
Key Values Property: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I get the Call to the Server but when i try to pull values from the Textbox they are coming back as Null that it cant find thought controls. I have search for hours on the forum and tried various thing and just cat seem to get it to work here is the Code.
NOTE: server side i get these 2 error for (THIS IS ON AN INSERT)
GridEditableItem object
EditManger Property: The current EditFormType does not support the requested editing capabilities.Key Values Property: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
<telerik:RadGrid ID="TestimonialsGrid" runat="server" Skin="WebBlue" OnDataBound="TestimonialsGrid_DataBound" |
OnNeedDataSource="TestimonialsGrid_NeedDataSource" AutoGenerateColumns="false" |
ShowStatusBar="true" oninsertcommand="TestimonialsGrid_InsertCommand"> |
<MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" PagerStyle-AlwaysVisible="true" |
DataKeyNames="Testimonial_ID" EditMode="PopUp"> |
<CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add A New Testimonial" /> |
<RowIndicatorColumn Visible="True"> |
</RowIndicatorColumn> |
<Columns> |
<telerik:GridBoundColumn DataField="Testimonial_ID" Display="false" HeaderText="ID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Testimonial_Name" Display="true" HeaderText="Name" |
Groupable="true"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Testimonial_Email" Display="true" HeaderText="Email" |
Groupable="true"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Testimonial_Text" Display="true" HeaderText="Text" |
Groupable="true"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Testimonial_Approved" Display="true" HeaderText="Approved" |
Groupable="true"> |
</telerik:GridBoundColumn> |
<telerik:GridDateTimeColumn DataField="Testimonial_CreateDate" Display="true" HeaderText="Create Date" |
Groupable="true"> |
</telerik:GridDateTimeColumn> |
</Columns> |
<EditFormSettings EditFormType="Template"> |
<PopUpSettings Modal="True"></PopUpSettings> |
<FormTemplate> |
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0"> |
<tr> |
<td align="right" valign="top"> |
</td> |
<td> |
<asp:ValidationSummary ID="valSumTestimonial" runat="server" DisplayMode="BulletList" |
HeaderText="Please correct the following error(s): " ShowSummary="false" ShowMessageBox="true" /> |
</td> |
</tr> |
<tr> |
<td align="right" valign="top"> |
<asp:RequiredFieldValidator ID="reqValName" runat="server" ErrorMessage="Display Name is required." |
Text="*" ControlToValidate="txtDisplayName" InitialValue="" SetFocusOnError="false" |
Display="Dynamic"></asp:RequiredFieldValidator>Display Name: |
</td> |
<td> |
<telerik:RadTextBox ID="txtDisplayName" runat="server" Text='<%# Bind( "Testimonial_Name") %>' |
TextMode="MultiLine" Rows="3" Columns="50" MaxLength="500" EmptyMessage="(What you place will be displayed as the name) \\r\\n \r\n Suggestion: Name, company name and position, city, state."> |
</telerik:RadTextBox> |
</td> |
</tr> |
<tr> |
<td align="right" valign="top"> |
<asp:RequiredFieldValidator ID="reqValEmail" runat="server" ErrorMessage="Email is required." |
Text="*" ControlToValidate="txtEmailAddress" InitialValue="" Display="Dynamic"></asp:RequiredFieldValidator><asp:RegularExpressionValidator |
ID="regValEmail" runat="server" ErrorMessage="Email is in an incorrect format." |
Text="*" ControlToValidate="txtEmailAddress" Display="dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>Email: |
</td> |
<td> |
<telerik:RadTextBox ID="txtEmailAddress" runat="server" Text='<%# Bind( "Testimonial_Email") %>' |
MaxLength="500" Width="315px" EmptyMessage="(Email is NOT shared or displayed on the website)"> |
</telerik:RadTextBox> |
</td> |
</tr> |
<tr> |
<td align="right" valign="top"> |
<asp:RequiredFieldValidator ID="reqValTestimonial" runat="server" ErrorMessage="Testimonial Message is required." |
Text="*" ControlToValidate="txtTestimonial" InitialValue="" SetFocusOnError="false" |
Display="Dynamic"></asp:RequiredFieldValidator>Testimonial: |
</td> |
<td> |
<telerik:RadTextBox ID="txtTestimonial" runat="server" Text='<%# Bind( "Testimonial_Text") %>' |
TextMode="MultiLine" Rows="10" Columns="50" MaxLength="500" EmptyMessage="Type Your Testimonial Here!"> |
</telerik:RadTextBox> |
</td> |
</tr> |
<tr> |
<td align="right" valign="top"> |
</td> |
<td> |
<telerik:RadCaptcha ID="RadCaptcha1" runat="server" Display="Dynamic" ProtectionMode="InvisibleTextBox"> |
</telerik:RadCaptcha> |
</td> |
</tr> |
</table> |
<table style="width: 100%"> |
<tr> |
<td align="right" colspan="2"> |
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' |
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> |
</asp:Button> |
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" |
CommandName="Cancel"></asp:Button> |
</td> |
</tr> |
</table> |
</FormTemplate> |
</EditFormSettings> |
<PagerStyle AlwaysVisible="True"></PagerStyle> |
</MasterTableView> |
<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True"> |
<Selecting AllowRowSelect="True"></Selecting> |
<Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True" |
ResizeGridOnColumnResize="False"></Resizing> |
</ClientSettings> |
<GroupingSettings ShowUnGroupButton="true" /> |
<PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" /> |
</telerik:RadGrid> |
private SQL oSQL = new SQL(); |
private string gridMessage = null; |
protected void Page_Load(object sender, EventArgs e) |
{ |
} |
protected void TestimonialsGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
{ |
LoadTestimonialsGrid(); |
} |
private void LoadTestimonialsGrid() |
{ |
oSQL = Testimonial.GetAllTestimonials(); |
TestimonialsGrid.DataSource = oSQL.SQL_DataReader; |
} |
protected void TestimonialsGrid_DataBound(object sender, EventArgs e) |
{ |
oSQL.CloseConnection(); |
//if (!string.IsNullOrEmpty(gridMessage)) |
//{ |
DisplayMessage(gridMessage); |
//} |
} |
private void SetMessage(string message) |
{ |
gridMessage = message; |
} |
private void DisplayMessage(string text) |
{ |
TestimonialsGrid.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text))); |
} |
protected void TestimonialsGrid_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
if (e.CommandName == RadGrid.PerformInsertCommandName) |
{ |
SetMessage("New Testimonial Added!"); |
GridEditableItem editedItem = e.Item as GridEditableItem; |
GridEditFormInsertItem e2 = e.Item as GridEditFormInsertItem; |
GridEditFormItem e3 = e.Item as GridEditFormItem; |
//Insert new values |
Testimonial oTestimonial = new Testimonial(); |
TextBox tb = e2.FindControl("txtDisplayName") as TextBox; |
TextBox tb2 = e3.FindControl("txtDisplayName") as TextBox; |
TextBox tb3 = e.Item.FindControl("txtDisplayName") as TextBox; |
//TextBox tb4 = e2["Testimonial_Name"].Controls[0] as TextBox; |
oTestimonial.Display_Name = (editedItem.FindControl("txtDisplayName") as TextBox).Text; |
//oTestimonial.Email_Address = (editedItem.FindControl("txtEmailAddress") as TextBox).Text; |
//oTestimonial.Message = (editedItem.FindControl("txtTestimonial") as TextBox).Text; |
//oTestimonial.Approved = "N"; |
//oTestimonial.Create_Date = DateTime.Now; |
//oTestimonial.InsertTestimonial(); |
} |
} |