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

RadGrid

4 Answers 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
nisha
Top achievements
Rank 1
nisha asked on 01 Jul 2010, 10:55 AM
Hi, I'm using RadGrid for inserting and updating data. I have enabled AutoGenerateEditColumns to true. But when I edit data, its not updating the data back. I have a stored procedure to update data in the business layer and from

RadGrid1_ItemUpdated

event i'm calling that function. But control is not going inside  RadGrid1_ItemUpdated event. I'm binding the grid dynamically from oracle database. Any help would be appreciated.
Aspx:

 

<

 

asp:UpdatePanel ID="UpdatePanel1" runat="server">

 

 

 

 

 

<ContentTemplate>

 

 

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" PageSize="5"

 

 

Width="612px" AutoGenerateEditColumn="True"

 

 

oniteminserted="RadGrid1_ItemInserted" onitemupdated="RadGrid1_ItemUpdated"

 

 

onneeddatasource="RadGrid1_NeedDataSource">

 

 

 

 

 

<PagerStyle AlwaysVisible="True" />

 

<

 

MasterTableView>

 

<

 

RowIndicatorColumn>

 

<

 

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

 

</

 

RowIndicatorColumn>

 

<

 

ExpandCollapseColumn>

 

<

 

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

 

</

 

ExpandCollapseColumn>

 

 

 

 

 

<PagerStyle AlwaysVisible="True" />

 

</

 

MasterTableView>

 

 

 

 

 

<EditItemStyle BackColor="#FFFF66" BorderColor="Black" BorderStyle="Solid" />

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 

 

</ContentTemplate>

 

 

 

 

 

</asp:UpdatePanel>

 


aspx.cs file:

protected

 

void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)

 

{

 

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)

 

{

BAL.

BAL balobj = newBAL.BAL();  //Business layer object

 

 

int flag = 0;

 

 

GridEditableItem item = (GridEditableItem)e.Item;

 

 

string cty = item.GetDataKeyValue("city_name").ToString();

 

 

string id = item.GetDataKeyValue("city_id").ToString();

 

 

//calling validation function

 

flag = balobj.validate_cityName(cty);

 

if (flag == 0)

 

{

balobj.New_City_Name = cty;

balobj.City_Id = int.Parse(id);

 

balobj.city_modify();

}

 

else

 

{

Label1.Visible =

true;

 

Label1.Text =

"<script>alert('City name already exists')</script>";

 

}

}

}

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 01 Jul 2010, 11:31 AM
Hello,

The events ItemUpdated/ ItemInserted/ ItemDeleted are fired only when an automatic data operations are performed. You can use try-catch statement in order to handle the exception in the case of manual update/insert/delete as shown in the code library.


-Shinu.
0
nisha
Top achievements
Rank 1
answered on 01 Jul 2010, 12:13 PM
Thanks for the reply. I'm trying this code but getting error for

(Telerik.WebControls.GridCommandEventArgs e). I couldn't able to add reference to Telerik.WebControl namespace. I'm using trial version. Where do I get this assembly?

0
nisha
Top achievements
Rank 1
answered on 01 Jul 2010, 12:45 PM
instead of (Telerik.WebControls.GridCommandEventArgs e), I used (Telerik.Web.Ui.GridCommandEventArgs e) and getting no errors. But I could not access the 2nd TextBox value in edit form.

GridEditableItem

 

editedItem = e.Item as GridEditableItem;

 

 

string cityname = (editedItem["CITY_NAME"].Controls[0] as TextBox).Text;

 

 

string cityId = (editedItem["CITY_ID"].Controls[0] as TextBox).Text;
I can get the cityname value from textbox but getting NullReferenceException: Object reference not set to an instance of an object. error for cityid. I'm not getting what is wrong in the above statement.
kindly help.

 

0
Pavlina
Telerik team
answered on 05 Jul 2010, 02:53 PM
Hi Sowmya,

When the grid item is in edit mode, you can use the column's UniqueName to access the cell (even if it is in an edit form). Then you can locate the control that contains the cell's value and, depending on the type of the column editor, cast it to the appropriate type, and access the value:

Please, refer to the help topic below for more information:
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
nisha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
nisha
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or