Hi, I'm using a radgrid with a FormTemplate that has many textboxes and a couple of other standard asp.net controls. One of the textboxes is for saving a password, before the insert is sent to the database I'd like to take the password text, hash it up then send the hash to the database (I'm using entity framework for accessing the db).
Problem is I seem to be able to do everything but actually save the record. Below is some of my code but
a) nothing gets to the db and
b) the grid stays in insert mode and the values clean out on clicking the "insert" like
Any any sight would be much appreciated.
<telerik:RadGrid ID="CandidateGrid" runat="server" AutoGenerateColumns="false" DataSourceID="CandidateData"
AllowFilteringByColumn="true" AllowPaging="true" OnItemCommand="CandidateGrid_Command" OnInsertCommand="CandidateGrid_Insert">
<PagerStyle Mode="NumericPages" Visible="true" />
<MasterTableView DataSourceID="CandidateData" DataKeyNames="OptimumUserId" AllowMultiColumnSorting="true"
GroupLoadMode="Server" AllowAutomaticUpdates="true" AllowAutomaticInserts="true"
CommandItemDisplay="Top">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="../Assets/Images/document_edit.png" />
<telerik:GridCheckBoxColumn DataField="IsActive" HeaderText="Active" />
<telerik:GridBoundColumn DataField="OptimumPayrollId" HeaderText="Payroll Id" />
<telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" />
<telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" />
<telerik:GridBoundColumn DataField="Email" HeaderText="Email" />
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td>
Active:
</td>
<td class="required">
*
</td>
<td>
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='' />
</td>
</tr>
<tr>
<td>
Payroll Id:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="PayrollIdTextBox" runat="server" Text='<%# Bind("OptimumPayrollId") %>' />
<asp:RequiredFieldValidator ID="PayrollIdTextBoxValidation" runat="server" ControlToValidate="PayrollIdTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<asp:RequiredFieldValidator ID="FirstNameValidation" runat="server" ControlToValidate="FirstNameTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Surname:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="SurnameTextBox" runat="server" Text='<%# Bind("Surname") %>' />
<asp:RequiredFieldValidator ID="SurnameValidation" runat="server" ControlToValidate="SurnameTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<asp:RequiredFieldValidator ID="EmailValidation" runat="server" ControlToValidate="EmailTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="PasswordTextBox" runat="server" Text='' />
<asp:RequiredFieldValidator ID="PasswordValidation" runat="server" ControlToValidate="PasswordTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:LinkButton ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:LinkButton>
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:LinkButton>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
...
protected void CandidateGrid_Insert(object source, GridCommandEventArgs e)
{
e.Canceled = true;
ListDictionary newValues = new ListDictionary();
OptimumProviders.MembershipProvider p = new MembershipProvider();
GridEditableItem editedItem = e.Item.OwnerTableView.GetInsertItem();
string password = (editedItem.FindControl("PasswordTextBox") as TextBox).Text;
bool isActive = (editedItem.FindControl("ActiveCheckBox") as CheckBox).Checked;
string encodedPassword = p.EncodePassword(password);
newValues["Password"] = encodedPassword;
newValues["IsActive"] = isActive;
e.Item.OwnerTableView.InsertItem(newValues);
}
Problem is I seem to be able to do everything but actually save the record. Below is some of my code but
a) nothing gets to the db and
b) the grid stays in insert mode and the values clean out on clicking the "insert" like
Any any sight would be much appreciated.
<telerik:RadGrid ID="CandidateGrid" runat="server" AutoGenerateColumns="false" DataSourceID="CandidateData"
AllowFilteringByColumn="true" AllowPaging="true" OnItemCommand="CandidateGrid_Command" OnInsertCommand="CandidateGrid_Insert">
<PagerStyle Mode="NumericPages" Visible="true" />
<MasterTableView DataSourceID="CandidateData" DataKeyNames="OptimumUserId" AllowMultiColumnSorting="true"
GroupLoadMode="Server" AllowAutomaticUpdates="true" AllowAutomaticInserts="true"
CommandItemDisplay="Top">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="../Assets/Images/document_edit.png" />
<telerik:GridCheckBoxColumn DataField="IsActive" HeaderText="Active" />
<telerik:GridBoundColumn DataField="OptimumPayrollId" HeaderText="Payroll Id" />
<telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" />
<telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" />
<telerik:GridBoundColumn DataField="Email" HeaderText="Email" />
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td>
Active:
</td>
<td class="required">
*
</td>
<td>
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='' />
</td>
</tr>
<tr>
<td>
Payroll Id:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="PayrollIdTextBox" runat="server" Text='<%# Bind("OptimumPayrollId") %>' />
<asp:RequiredFieldValidator ID="PayrollIdTextBoxValidation" runat="server" ControlToValidate="PayrollIdTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="FirstNameTextBox" runat="server" Text='<%# Bind("FirstName") %>' />
<asp:RequiredFieldValidator ID="FirstNameValidation" runat="server" ControlToValidate="FirstNameTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Surname:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="SurnameTextBox" runat="server" Text='<%# Bind("Surname") %>' />
<asp:RequiredFieldValidator ID="SurnameValidation" runat="server" ControlToValidate="SurnameTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<asp:RequiredFieldValidator ID="EmailValidation" runat="server" ControlToValidate="EmailTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td class="required">
*
</td>
<td>
<asp:TextBox ID="PasswordTextBox" runat="server" Text='' />
<asp:RequiredFieldValidator ID="PasswordValidation" runat="server" ControlToValidate="PasswordTextBox"
ErrorMessage="Required" />
</td>
</tr>
<tr>
<td colspan="3">
<asp:LinkButton ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:LinkButton>
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:LinkButton>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
...
protected void CandidateGrid_Insert(object source, GridCommandEventArgs e)
{
e.Canceled = true;
ListDictionary newValues = new ListDictionary();
OptimumProviders.MembershipProvider p = new MembershipProvider();
GridEditableItem editedItem = e.Item.OwnerTableView.GetInsertItem();
string password = (editedItem.FindControl("PasswordTextBox") as TextBox).Text;
bool isActive = (editedItem.FindControl("ActiveCheckBox") as CheckBox).Checked;
string encodedPassword = p.EncodePassword(password);
newValues["Password"] = encodedPassword;
newValues["IsActive"] = isActive;
e.Item.OwnerTableView.InsertItem(newValues);
}