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

[Solved] how to find GridEditCommandColumn in code-behind

3 Answers 469 Views
Grid
This is a migrated thread and some comments may be shown as answers.
beigel
Top achievements
Rank 1
beigel asked on 28 May 2009, 03:47 PM
Hello,

I have a RadGrid with GridEditCommandColumn inside ajaxToolkit:ModalPopupExtender panel. RadGrid is populated with asp ObjectDataSource, which has insert/update/delete methods triggered every time I click on a button in RadGrid ('Edit' button of the GridEditCommandColumn, for example). When an Update event is fired, all my controls inside the panel and including the panel itself are null, so I found a workaround and use RadGrid_ItemCommand function instead. This way I can set and validate my contols, and I can get an index in the grid and an event name fired.

My problem is that I have to use Request.Params to find changed Name on Edit, and this is not a good programming practice (even though it works). How can I replace Request.Params or at least set a name for the GridEditCommandColumn?

 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
...

if (Request.Params["__EVENTTARGET"].Contains("UpdateButton"))

 

 

int index = e.Item.DataSetIndex;

 

int locationID = CurrentClub.Locations[index].LocationId;

ValidateUpdatedItem(locationID, Request.Params.Get(

 

 

"ctl00$ctl00$phBody$phBody$ucEditEventLoc$rgLocations$ctl00$ctl09$ctl00"));

}

 

 

else

 

if (Request.Params["__EVENTTARGET"].Contains("PerformInsertButton"))

ValidateNewItem(Request.Params.Get(

 

 

"ctl00$ctl00$phBody$phBody$ucEditEventLoc$rgLocations$ctl00$ctl02$ctl02$ctl00"));
}

----------------------------------- ascx page

<

 

 

telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">

 

<AjaxSettings>

 

 

 

 

<telerik:AjaxSetting AjaxControlID="rgLocations">

 

 

 

 

<UpdatedControls>

 

 

 

 

<telerik:AjaxUpdatedControl ControlID="rgLocations" />

 

 

 

 

<telerik:AjaxUpdatedControl ControlID="lblErrorMessage" />

 

 

 

 

</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>

 

 

 

 

 

<ajaxToolkit:ModalPopupExtender ID="mdlPopupLocation" runat="server" PopupControlID="pnLocation"

 

 

 

 

BackgroundCssClass="modalBackground" TargetControlID="btnAddLocation">

 

 

 

 

 </ajaxToolkit:ModalPopupExtender>

 

 

 

 

 

<asp:Panel runat="server" ID="pnLocation" CssClass="pnlPop" Style="display: none;EnableViewState="true">

 

 

 

 

<telerik:RadGrid ID="rgLocations" runat="server" GridLines="None" AllowPaging="True" AllowSorting="False" DataSourceID="objDSLocations" AutoGenerateColumns="False" AllowAutomaticDeletes="True"

 

 

 

 

AllowAutomaticInserts="True" AllowAutomaticUpdates="True" HorizontalAlign="NotSet"

 

 

 

 

ShowStatusBar="false" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand">

 

 

 

 

<MasterTableView DataKeyNames="LocationId" CommandItemDisplay="Bottom" CommandItemSettings-RefreshImageUrl=""

 

 

 

 

CommandItemSettings-RefreshText="" GridLines="None" Width="100%" EditMode="InPlace">

 

 

 

 

<Columns>
<telerik:GridBoundColumn UniqueName="LocationName" EditFormColumnIndex="0" HeaderText="Location Name"  DataField="Name"> </telerik:GridBoundColumn>

 

 

 

 

<telerik:GridEditCommandColumn UniqueName="editcmdColumnLoc">

 

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

 

<telerik:GridButtonColumn Text="Delete" CommandName="Delete"  UniqueName= "DeleteColumn"></telerik:GridButtonColumn>

 

 

 

 

</Columns>

 

 

 

 

<ExpandCollapseColumn ButtonType="ImageButton" Visible="False" UniqueName="ExpandColumn">

 

 

 

 

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

 

 

 

 

</ExpandCollapseColumn>

 

 

 

</MasterTableView>  

 

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>

 

</telerik:RadGrid>

 

 

 

<asp:ObjectDataSource ID="objDSLocations" runat="server" SelectMethod="SelectLocations"

 

 

 

 

InsertMethod="InsertLocations" UpdateMethod="UpdateLocations" TypeName="CHO.Next.WebUI.UserControls.Events.EditEventLocation">

 

 

 

 

<UpdateParameters>

 

 

 

<asp:Parameter Name="LocationId" Type="Int32" />

 

<asp:Parameter Name="Name" Type="String" />

 

 

</UpdateParameters>

 

 

 

<InsertParameters>

 

<asp:Parameter Name="Name" Type="String" />

 

</InsertParameters>

 

 

</asp:ObjectDataSource>

 

 

 

 

 

 

Thank you

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 01 Jun 2009, 10:21 AM
Hello beigel,

You can detect the update command/insert command inside the ItemCommand handler by checking whether e.CommandName is RadGrid.UpdateCommandName or RadGrid.PerformInsertCommandName. See the information from this documentation article for more details.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
beigel
Top achievements
Rank 1
answered on 02 Jun 2009, 06:57 PM
Okey, thank you

This way I can get my event name, but what about Edit text box name and value? How can I pull that info without using Request.Params?

ValidateUpdatedItem(locationID, Request.Params.Get("ctl00$ctl00$phBody$phBody$ucEditEventLoc$rgLocations$ctl00$ctl09$ctl00"));


Thank you!
0
Sebastian
Telerik team
answered on 03 Jun 2009, 11:22 AM
Hello beigel,

How to extract the new values from the edited/inserted grid item you can see from the following online demos of  the product:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx

Review the code snippets in the UpdateCommand/InsertCommand/ItemCommand handlers for more details.

Best,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
beigel
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
beigel
Top achievements
Rank 1
Share this question
or