5 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 May 2013, 04:48 AM
Hi Wella,
I guess you want to Group a RadGrid according to the SelectedValue of the External DropDownList. Please check the following code snippet.
ASPX:
C#:
Thanks,
Princy.
I guess you want to Group a RadGrid according to the SelectedValue of the External DropDownList. Please check the following code snippet.
ASPX:
<asp:DropDownList ID="DDl" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DDl_SelectedIndexChanged"> <asp:ListItem Text="OrderID" Value="OrderID"></asp:ListItem> <asp:ListItem Text="EmployeeID" Value="EmployeeID"></asp:ListItem></asp:DropDownList><telerik:RadGrid ID="Radgrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource2"> <MasterTableView> <Columns> <telerik:GridBoundColumn DataField="OrderID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="EmployeeID"> </telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void DDl_SelectedIndexChanged(object sender, EventArgs e){ string selectedvalue = DDl.SelectedValue; GridGroupByField field = new GridGroupByField(); field.FieldName = selectedvalue; field.HeaderText = selectedvalue; GridGroupByExpression ex = new GridGroupByExpression(); ex.GroupByFields.Add(field); ex.SelectFields.Add(field); Radgrid1.MasterTableView.GroupByExpressions.Add(ex); Radgrid1.Rebind();}Thanks,
Princy.
0
Wella
Top achievements
Rank 1
answered on 02 May 2013, 05:43 AM
Thank You very much for your answer but i got an error on this code in rebind call.
An error occured adding a relation to DataRelationCollection. Please, make sure you have configured the expressions properly - both GroupByFields and SelectFields are required!
please help to solve this
Thanks
An error occured adding a relation to DataRelationCollection. Please, make sure you have configured the expressions properly - both GroupByFields and SelectFields are required!
please help to solve this
Thanks
0
Princy
Top achievements
Rank 2
answered on 03 May 2013, 04:42 AM
Hi Wella,
Unfortunately I couldn't replicate the issue. Can you please provide your code.
Thanks,
Princy.
Unfortunately I couldn't replicate the issue. Can you please provide your code.
Thanks,
Princy.
0
Wella
Top achievements
Rank 1
answered on 03 May 2013, 05:02 AM
try
{
this.grid1.MasterTableView.GroupByExpressions.Clear();//clear all group expressions
grid1.MasterTableView.GroupsDefaultExpanded = false;
GridGroupByExpression expression = new GridGroupByExpression();
GridGroupByField gridGroupByField = new GridGroupByField();
gridGroupByField = new GridGroupByField();
if (cboGroupByItem1.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem1.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem1.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
if (cboGroupByItem2.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem2.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem2.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
grid1.MasterTableView.GroupByExpressions.Add(expression);
}
catch (Exception ex)
{
lblMessage.Text = ex.ToString();
}
finally
{
grid1.Rebind();
}
in need data source event i will set data source to grid
protected void grid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = getGridData();
grid1.DataSource = dt;
}
{
this.grid1.MasterTableView.GroupByExpressions.Clear();//clear all group expressions
grid1.MasterTableView.GroupsDefaultExpanded = false;
GridGroupByExpression expression = new GridGroupByExpression();
GridGroupByField gridGroupByField = new GridGroupByField();
gridGroupByField = new GridGroupByField();
if (cboGroupByItem1.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem1.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem1.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
if (cboGroupByItem2.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem2.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem2.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
grid1.MasterTableView.GroupByExpressions.Add(expression);
}
catch (Exception ex)
{
lblMessage.Text = ex.ToString();
}
finally
{
grid1.Rebind();
}
in need data source event i will set data source to grid
protected void grid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = getGridData();
grid1.DataSource = dt;
}
0
Princy
Top achievements
Rank 2
answered on 03 May 2013, 05:32 AM
Hi,
Can you provide the markup , i think you have two DropDownList. Please specify the event in with the above codes are written.
Thanks,
Princy.
Can you provide the markup , i think you have two DropDownList. Please specify the event in with the above codes are written.
Thanks,
Princy.