
Andy Stapleton
Top achievements
Rank 1
Andy Stapleton
asked on 22 Dec 2008, 01:51 AM
I am fairly new at ASPX programming and telerik,
I have updated the mastertable form to allow entries, placed a droplist on it for choice of type.
if anyone has a clue on what I need to do to access the value of that drop list, I would appreciate the help...
GridEditFormItem updItem = (GridEditFormItem)e.Item;
string iCussysid = Session["cussysid"].ToString();
// trying to get this value in iTypeAccount
string iTypeAccount = (updItem["TypeAccount"].Controls[0] as DropDownList).SelectedItem.Text;
// here
string iAcctBalance = (updItem["AcctBalance"].Controls[0] as TextBox).Text;
string iTradeAccountNo = (updItem["TradeAccountNo"].Controls[0] as TextBox).Text;
try
{
//Open the SqlConnection
string sqlStatement = "Update Dbo.CustomerAccounts "+
" Set TypeAccount = '"+iTypeAccount+"',"+
" AcctBalance = "+Convert.ToDecimal(iAcctBalance)+","+
" TradeAccountNo = " + Convert.ToInt32(iTradeAccountNo) +
" Where cussysid = "+Convert.ToInt32(iCussysid);
thanks.
7 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 22 Dec 2008, 06:49 AM
Hi Andy,
To access the value of a GridDropDownColumn you need to check whether the gird row is in edit mode. Try the following code snippet in the ItemDataBound event.
CS:
Thanks
Shinu
To access the value of a GridDropDownColumn you need to check whether the gird row is in edit mode. Try the following code snippet in the ItemDataBound event.
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
DropDownList list = (e.Item as GridEditableItem)["TypeAccount"].Controls[0] as DropDownList; |
string iTypeAccount=list.SelectedItem.Text; |
//... |
} |
} |
Thanks
Shinu
0

Andy Stapleton
Top achievements
Rank 1
answered on 22 Dec 2008, 10:17 AM
Specified argument was out of the range of valid values.
Parameter name: index
I am getting the above error.....
to CLarify, it is already in edit mode , I am in the InsertCommand method, looking to update the record.. see below.
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
string sqlStatement;
//Get the GridEditFormInsertItem of the RadGrid
GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
string iCussysid = Session["cussysid"].ToString();
string iAcctBalance = (insertedItem["AcctBalance"].Controls[0] as TextBox).Text;
string iTradeAccountNo = (insertedItem["TradeAccountNo"].Controls[0] as TextBox).Text;
0
Hi Andy,
Could you please send us your grid declaration? If your grid is ajaxified, try disabling the ajax and check if the error persists.
Let me know how it goes.
All the best,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Could you please send us your grid declaration? If your grid is ajaxified, try disabling the ajax and check if the error persists.
Let me know how it goes.
All the best,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Andy Stapleton
Top achievements
Rank 1
answered on 22 Dec 2008, 01:47 PM
<telerik:RadPageView ID="RadPageView2" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server"
AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True"
AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" GridLines="None"
Height="280px" OnInsertCommand="RadGrid1_InsertCommand" Skin="Gray" AutoGenerateDeleteColumn="True" OnItemUpdated="RadGrid1_ItemUpdated">
<HeaderContextMenu EnableTheming="True" Skin="Gray">
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="AccountNo"
DataSourceID="SqlDataSource1">
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Cussysid" DataType="System.Int32" HeaderText="Cussysid"
SortExpression="Cussysid" UniqueName="Cussysid" Visible="False">
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AccountNo" DataType="System.Int32" HeaderText="Account"
ReadOnly="True" SortExpression="AccountNo" UniqueName="AccountNo">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TypeAccount" HeaderText="Type Account" SortExpression="TypeAccount"
UniqueName="TypeAccount">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AcctBalance" DataType="System.Decimal" HeaderText="Balance"
SortExpression="AcctBalance" UniqueName="AcctBalance">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TradeAccountNo" DataType="System.Int32" HeaderText="Broker Acct"
SortExpression="TradeAccountNo" UniqueName="TradeAccountNo">
<HeaderStyle Width="100px" />
<ItemStyle Width="100px" />
</telerik:GridBoundColumn>
</Columns>
</FormTemplate>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td style="width: 100px">
Type Acct:</td>
<td colspan="2" style="text-align: left; width: 178px;">
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("TypeAccount") %>'>
<asp:ListItem>Personal</asp:ListItem>
<asp:ListItem>Demo</asp:ListItem>
<asp:ListItem>Managed</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px">
Acct Bal:</td>
<td colspan="2" style="width: 178px; text-align: left">
<asp:TextBox ID="acctBalance" runat="server" Text='<%# Bind("AcctBalance", "{0:C}") %>'></asp:TextBox>
</tr>
<tr>
<td style="width: 100px; height: 26px;">
Broker Acct:</td>
<td colspan="2" style="width: 178px; height: 26px; text-align: left">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TradeAccountNo", "{0}") %>'></asp:TextBox></td>
</tr>
<tr>
<td colspan="3" style="height: 26px; text-align: center">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
</asp:Button>
<asp:Button ID="btnAbort" runat="server" Text="Abort" CausesValidation="false" CommandName="Cancel"/></td>
</tr>
</table>
</EditFormSettings>
0
Hi Andy,
Try modifying your code as below and check if the error persists:
Additionally, I suggest that you review the below articles for more information:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html
http://demos.telerik.com/aspnet-ajax/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
Kind regards,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Try modifying your code as below and check if the error persists:
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) |
{ |
string sqlStatement; |
GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; |
string iCussysid = Session["cussysid"].ToString(); |
string iAcctBalance = (insertedItem.FindControl("accBalance") as TextBox).Text; |
string iTradeAccountNo = (insertedItem.FindControl("TextBox1") as TextBox).Text; |
} |
Additionally, I suggest that you review the below articles for more information:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html
http://demos.telerik.com/aspnet-ajax/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
Kind regards,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Andy Stapleton
Top achievements
Rank 1
answered on 22 Dec 2008, 03:39 PM
I apologize, the insertcommand works fine, it is the update command I cannot seem to get
protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)
{
GridEditFormItem updItem = (GridEditFormItem)e.Item;
string iCussysid = Session["cussysid"].ToString();
DropDownList list = (e.Item as GridEditableItem)["TypeAccount"].Controls[0] as DropDownList;
string iTypeAccount = list.SelectedItem.Text; // returns the error on index.
string iAcctBalance = (updItem["AcctBalance"].Controls[0] as TextBox).Text;
string iTradeAccountNo = (updItem["TradeAccountNo"].Controls[0] as TextBox).Text;
try
{
//Open the SqlConnection
string sqlStatement = "Update Dbo.CustomerAccounts "+
" Set TypeAccount = '"+iTypeAccount+"',"+
" AcctBalance = "+Convert.ToDecimal(iAcctBalance)+","+
" TradeAccountNo = " + Convert.ToInt32(iTradeAccountNo) +
" Where cussysid = "+Convert.ToInt32(iCussysid);
0
Hello Andy,
From the preceding code I can see that this is the ItemUpdated event handler but the UpdateCommand event one. Note that the ItemUpdated event is fired after the item is updated and it is already out of edit mode. To perform custom operations when the Update button is clicked, you need to handle the UpdateCommand instead. Find more about updating record with form template here.
Sincerely yours,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
From the preceding code I can see that this is the ItemUpdated event handler but the UpdateCommand event one. Note that the ItemUpdated event is fired after the item is updated and it is already out of edit mode. To perform custom operations when the Update button is clicked, you need to handle the UpdateCommand instead. Find more about updating record with form template here.
Sincerely yours,
Iana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.