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.