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

RadGrid with Ajax in Sharepoint 2010

5 Answers 159 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
vinitha
Top achievements
Rank 1
vinitha asked on 23 Jul 2010, 01:25 PM
Hi All,

I am facing a wierd issues.

Requirement:
1. On selecting anything in the dropdown list, grid and description panel should be updated. (As of now i am displaying the id in the description panel)
2. On selecting any row in the grid, description panel should be updated.

I have a web part which loads user control as given below.

protected

 

override void CreateChildControls()

 

{

 

base.CreateChildControls();

 

userControl = Page.LoadControl(

@"~\_layouts\UserControls\RadGridDemo.ascx");

 

Controls.Add(userControl);

}

In the user control, I have a drop down list, RadGrid and descriptionPanel controls defined as below.

<%

@ Control Language="C#" ClassName="RadGridDemo" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<%

@ Import Namespace="System" %>

 

<%

@ Import Namespace="System.Data" %>

 

<%

@ Import Namespace="Telerik.Web.UI" %>

 

<

 

div>

 

 

<div>

 

 

<asp:PlaceHolder ID="Pl" runat="server">

 

 

<telerik:RadAjaxManager ID="AjaxManager" runat="server">

 

 

<ajaxsettings>

 

 

<telerik:AjaxSetting AjaxControlID="MyTrainingDDList">

 

 

<UpdatedControls>

 

<%

-- <telerik:AjaxUpdatedControl ControlID="Grid1" />--%>

 

 

<telerik:AjaxUpdatedControl ControlID="DescPanel" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

<telerik:AjaxSetting AjaxControlID="Grid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="DescPanel" />

 

 

<telerik:AjaxUpdatedControl ControlID="Grid1" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</ajaxsettings>

 

 

</telerik:RadAjaxManager>

 

 

<asp:DropDownList ID="DDList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDList_SelectedIndexChanged">

 

 

<asp:ListItem Text="Customers" Selected="True"></asp:ListItem>

 

 

<asp:ListItem Text="Employees"></asp:ListItem>

 

 

</asp:DropDownList>

 

 

<telerik:RadGrid runat="server" ID="Grid1" OnSelectedIndexChanged="Grid1_SelectedIndexChanged">

 

 

<clientsettings enablerowhoverstyle="true" enablepostbackonrowclick="true" allowexpandcollapse="true">

 

 

<Selecting AllowRowSelect="True"></Selecting>

 

 

</clientsettings>

 

 

</telerik:RadGrid>

 

 

</asp:PlaceHolder>

 

 

</div>

 

 

<div id="DescPanel" runat="server">

 

 

<asp:Label ID="lblName" runat="server">

 

 

</asp:Label>

 

 

</div>

 

</

 

div>

 

<

 

script runat="server">

 

 

 

int trainingId = 0;

 

 

DataSet ds = null;

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

if (!IsPostBack)

 

{

Grid1.MasterTableView.DataKeyNames =

new String[] { "ID" };

 

SetData(0);

}

}

 

private void SetData(int index)

 

{

 

DataTable dt;

 

 

if (index == 0)

 

dt = GetCustomers();

 

else

 

dt = GetEmployees();

Grid1.DataSource = dt;

Grid1.Rebind();

 

if (Grid1.Items.Count > 0)

 

{

Grid1.SelectedIndexes.Add(0);

trainingId =

int.Parse(Grid1.MasterTableView.DataKeyValues[0]["ID"].ToString());

 

lblName.Text = trainingId.ToString();

}

 

else

 

lblName.Text =

"";

 

}

 

private DataTable GetEmployees()

 

{

 

DataTable dt = new DataTable("Employee");

 

dt.Columns.Add(

"Id");

 

dt.Columns.Add(

"FirstName");

 

dt.Columns.Add(

"LastName");

 

 

for (int i = 1; i <= 10; i++)

 

{

 

DataRow dr = dt.NewRow();

 

dr[

"Id"] = i.ToString();

 

dr[

"FirstName"] = "XXX" + i.ToString();

 

dr[

"LastName"] = "YYYY" + i.ToString();

 

dt.Rows.Add(dr);

}

 

return dt;

 

}

 

private DataTable GetCustomers()

 

{

 

DataTable dt = new DataTable("Customers");

 

dt.Columns.Add(

"Id");

 

dt.Columns.Add(

"FirstName");

 

dt.Columns.Add(

"LastName");

 

 

for (int i = 1; i <= 10; i++)

 

{

 

DataRow dr = dt.NewRow();

 

dr[

"Id"] = i.ToString();

 

dr[

"FirstName"] = "CCC" + i.ToString();

 

dr[

"LastName"] = "DDDDD" + i.ToString();

 

dt.Rows.Add(dr);

}

 

return dt;

 

}

 

protected void Grid1_SelectedIndexChanged(object source, System.EventArgs e)

 

{

 

int itemIndex = Grid1.SelectedItems[0].ItemIndex;

 

trainingId =

int.Parse(Grid1.MasterTableView.DataKeyValues[itemIndex]["ID"].ToString());

 

lblName.Text = trainingId.ToString();

}

 

protected void DDList_SelectedIndexChanged(object sender, EventArgs e)

 

{

 

int index = DDList.SelectedIndex;

 

SetData(index);

}

</

 

script>

 


When i deployed the user control and web part in SharePoint 2010, I am able to view the data but i face 2 issues in this.
1. First time, when i select anything in the dropdownlist or select any row in the grid, its not ajaxified but full post back is happening. Second time on wards it works perfectly fine.
2. I want ajax on ddl and grid but when i uncomment the line that is commented above, I am able to select a row in the grid only for the first time. From second time onwards, i am unable to select.

Please do help me resolving this. I am using the trial version of Telerik.Web.UI.dll 2010.2.713.20

Please do send me a sample which does the similar functionality.

Thanks in advance.



5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Jul 2010, 02:09 PM
Hello vinitha,

Attached is a small sample. I'd like to pay your attention to a couple of points:

1. You need to use Advanced databinding for your grid.

2. You need to add the RadAjaxManager control to the Items collection of the Page as described in the following help article:
http://www.telerik.com/help/aspnet-ajax/create-ajax-enabled-sharepoint-webpart-radcontrols.html

Hope it helps.

Regards,
Tsvetoslav
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
0
vinitha
Top achievements
Rank 1
answered on 27 Jul 2010, 08:17 AM
Hi,

Thanks for your response.

I tried using "Advanced databinding" as well as adding radAjaxManager to the Page.Items collection. Still i am facing the same issue.

The sample user control works perfectly fine when called in an aspx page. But doesnt work as expected when integrated with SharePoint site.

Please do guide me to resolve this issue.

Thanks in advance
0
Tsvetoslav
Telerik team
answered on 27 Jul 2010, 08:33 AM
Hi vinitha,

Could you send your web part implementation by opening a formal support ticket. I will debug it on my side and get back to you with more information. My sample works all right on my side.

Best wishes,
Tsvetoslav
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
0
Dragan
Top achievements
Rank 1
answered on 18 Nov 2010, 01:44 AM
Hi, I tried to use the attcahed Web part project. In addition I added Telerik.Web.UI to the server gac and added Safecontrol tag to SharePoint Web.config as below:
<SafeControl Assembly="Telerik.Web.UI, Version=2010.3.1109.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TypeName="*" Safe="True" SafeAgainstScript="True" />

and
<add verb="*" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" /> 
to nttpHandlers tag.

When I tried to add the web part to th epage I get exception:
"Could not load file or assembly 'Telerik.Web.UI' or one of its dependencies. The system cannot find the file specified."
at the line: 

 

Control control = Page.LoadControl(_ascxPath);

 

in the VisualWebPart1, CreateChildControls.

What else do I need to do in order to make this work?

Thanks.
Dragan

 

0
Tsvetoslav
Telerik team
answered on 22 Nov 2010, 11:09 AM
Hello Dragan,

Did you manage to open a ticket?

Best wishes,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Sharepoint Integration
Asked by
vinitha
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
vinitha
Top achievements
Rank 1
Dragan
Top achievements
Rank 1
Share this question
or