This is a migrated thread and some comments may be shown as answers.

[Solved] Unable to get the edited value of controls from Radgrid

5 Answers 278 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kaushik Subramanya
Top achievements
Rank 1
Kaushik Subramanya asked on 02 Sep 2009, 02:26 PM
Hello,
I am working on the evaluation copy of the Radgrid

I have a created a radgrid with editing capabilities. Once the user updates the item I am unable to get the edited values.

My code is listed below

ASPX Code

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"

 

 

 

 

 

OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

 

 

 

AllowSorting="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"

 

 

 

 

 

AutoGenerateEditColumn="true" OnItemUpdated="RadGrid1_ItemUpdated" OnUpdateCommand="RadGrid1_UpdateCommand">

 

 

 

 

 

<MasterTableView DataKeyNames="username" Width="100%" EditMode="InPlace">

 

 

 

 

 

<RowIndicatorColumn>

 

 

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

 

 

</RowIndicatorColumn>

 

 

 

 

 

<ExpandCollapseColumn>

 

 

 

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

 

 

 

</ExpandCollapseColumn>

 

 

 

 

 

<Columns>

 

 

 

 

 

<telerik:GridBoundColumn DataField="username" HeaderText="User Name" UniqueName="username" ReadOnly=true>

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

<telerik:GridBoundColumn DataField="password" HeaderText="Password" UniqueName="password">

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

<telerik:GridTemplateColumn HeaderText="Password" UniqueName="TemplateColumn">

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

<asp:DropDownList ID="DropDownList1" runat="server">

 

 

 

 

 

</asp:DropDownList>

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

</Columns>

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

</telerik:RadGrid>

 

 

 

C# Code

protected

 

void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)

 

{

 

//Get the GridEditableItem of the RadGrid

 

 

 

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

//Get the primary key value using the DataKeyValue.

 

 

 

 

 

string sUserName = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["username"].ToString();

 

 

//Access the textbox from the edit form template and store the values in string variables.

 

 

 

 

 

string sPassword = (editedItem["password"].Controls[0] as TextBox).Text;

 

}

 

Any help is much appreciated.

Regards,
Kaushik 

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 03 Sep 2009, 08:50 AM
Hi Kaushik,

To achieve the wanted behavior in the UpdateCommand event of RadGrid, you need to access your edit form's control values and update the data source manually, as described in this help article:
Insert/Update/Delete at database level with queries

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kaushik Subramanya
Top achievements
Rank 1
answered on 03 Sep 2009, 01:20 PM
Pavlina,
Thank you for sharing the link. It was very helpful and I was able to get the data from most of the columns.

Based on the website you mentioned I am getting an exception thrown (Null Pointer) when I am trying to read a DataKeyValue from the Hyperlinked column GridHyperLinkColumn

Below is my code. 

ASPX Page
<telerik:RadGrid ID="Rad_Grid1" runat="server" AllowSorting="True"
                     GridLines="None" AllowMultiRowEdit="True" AllowMultiRowSelection="True"
                     AutoGenerateColumns="False" AutoGenerateEditColumn="True" AllowPaging="True"
                AllowCustomPaging="True" PageSize="25"
                     onupdatecommand="Rad_Grid1_UpdateCommand">
                     <MasterTableView EditMode="InPlace" DataKeyNames="UniqueId">
                         <Columns>
                             <telerik:GridBoundColumn DataField="ContractNo"
                                 HeaderText="Contract Number" UniqueName="ContractNo">
                                 <FooterStyle Font-Bold="True" />
                                 <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                                     Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
                                     Wrap="True" />
                                 <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                                     Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
                                     Wrap="True" />
                             </telerik:GridBoundColumn>
                             <telerik:GridHyperLinkColumn DataNavigateUrlFields="UniqueId,RevisionNo"
                                 DataNavigateUrlFormatString="~/UpdateDetail.aspx?UniqueID={0}&amp;RevisionNo={1}&amp; 
                                 DataTextField="UniqueId" HeaderText="Unique ID" UniqueName="UniqueId">
                                 <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                                     Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
                                     Wrap="True" />
                                 <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                                     Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
                                     Wrap="True" />
                             </telerik:GridHyperLinkColumn>
                           </Columns>
                     </MasterTableView>
                 </telerik:RadGrid>

.CS Page

protected void Rad_Grid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
            GridDataItem hyperlinkItem = e.Item as GridDataItem;
            GridEditableItem editedItem = e.Item as GridEditableItem;
            //Get the primary key value using the DataKeyValue.     
            string sUniqueID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["UniqueID"].ToString();

            //Access the textbox from the edit form template and store the values in string variables.
            string sContractNo = (editedItem["ContractNo"].Controls[0] as TextBox).Text;
            string sRevisionNo = (editedItem["RevisionNo"].Controls[0] as TextBox).Text;
        }


It is throwing a null pointer error at the following line 
string sUniqueID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["UniqueID"].ToString();

Please advise

Regards,
Kaushik
0
Pavlina
Telerik team
answered on 04 Sep 2009, 03:36 PM
Hi Kaushik,

I went through your code and it looks fine to me. At this point in order to progress in the resolution of this problem I will ask you to open a formal support ticket and send us a simple runnable application that shows this issue. So I could help you in resolving it.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kaushik Subramanya
Top achievements
Rank 1
answered on 04 Sep 2009, 03:49 PM
Pavlina,
I am able to retrieve the edited value of controls now.

However I am still having issues from AJAX within Radgrid

Regards,
Kaushik
0
Pavlina
Telerik team
answered on 07 Sep 2009, 08:49 AM
Hi Kaushik,

I am happy to hear you were able to retrieve the edited value of controls.
We will continue our communication in the forum post for RadAjaxManager error.

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Kaushik Subramanya
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Kaushik Subramanya
Top achievements
Rank 1
Share this question
or