I am trying to use the CommandItem to add a new record to my grid. But when I process the "RadGrid2_ItemCommand" event in my code-behind, the textbox I entered a value into does not contain the text.
My procees is this: I click the "add new record" link and the insert template displays where I can type in my field data. I click insert and it goes to the Radgrid2_itemcommand event. But the Text property of the textbox is empty.
Thoughts?
Here is the radgrid (simplified)...
<telerik:RadGrid ID="RadGrid2" runat="server" PageSize="20" AllowPaging="True" AllowSorting="True"
GridLines="None" AllowFilteringByColumn="True" AutoGenerateColumns="false" OnItemDataBound="RadGrid2_ItemDataBound"
OnItemCommand="RadGrid2_ItemCommand">
<ClientSettings>
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="ProposalName" DataType="system.string" HeaderText="Proposal Id"
ReadOnly="True" SortExpression="ProposalName" UniqueName="ProposalName">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
Proposal Id:
</td>
<td>
<asp:TextBox ID="TextBoxInsertedProposalName" Text='<%# Bind( "ProposalName" ) %>'
runat="server" />
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Here is my code-behind...
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName) // after the user clicks "insert"
{
GridEditableItem editedItem = e.Item.OwnerTableView.GetInsertItem();
string insertedProposalName = (editedItem.FindControl("TextBoxInsertedProposalName") as TextBox).Text;
// this should have the value ABCD but instead has the value string.empty
Hashtable newValues = new Hashtable();
foreach (DictionaryEntry entry in newValues)
{
string key = entry.Key.ToString();
if (key == "ProposalName")
{
string value = entry.Value.ToString();
Debug.Print(key + " = " + value);
break;
}
}
}
}
My procees is this: I click the "add new record" link and the insert template displays where I can type in my field data. I click insert and it goes to the Radgrid2_itemcommand event. But the Text property of the textbox is empty.
Thoughts?
Here is the radgrid (simplified)...
<telerik:RadGrid ID="RadGrid2" runat="server" PageSize="20" AllowPaging="True" AllowSorting="True"
GridLines="None" AllowFilteringByColumn="True" AutoGenerateColumns="false" OnItemDataBound="RadGrid2_ItemDataBound"
OnItemCommand="RadGrid2_ItemCommand">
<ClientSettings>
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="ProposalName" DataType="system.string" HeaderText="Proposal Id"
ReadOnly="True" SortExpression="ProposalName" UniqueName="ProposalName">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
Proposal Id:
</td>
<td>
<asp:TextBox ID="TextBoxInsertedProposalName" Text='<%# Bind( "ProposalName" ) %>'
runat="server" />
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Here is my code-behind...
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName) // after the user clicks "insert"
{
GridEditableItem editedItem = e.Item.OwnerTableView.GetInsertItem();
string insertedProposalName = (editedItem.FindControl("TextBoxInsertedProposalName") as TextBox).Text;
// this should have the value ABCD but instead has the value string.empty
Hashtable newValues = new Hashtable();
foreach (DictionaryEntry entry in newValues)
{
string key = entry.Key.ToString();
if (key == "ProposalName")
{
string value = entry.Value.ToString();
Debug.Print(key + " = " + value);
break;
}
}
}
}