4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 02 May 2008, 11:04 AM
Hi John,
Try rebinding the Grid in the SelectedIndexChanged event of the DropDownList as shown below.
CS:
Thanks
Princy.
Try rebinding the Grid in the SelectedIndexChanged event of the DropDownList as shown below.
CS:
| protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| RadGrid1.Rebind(); |
| } |
Thanks
Princy.
0
Hello,
The following article includes more information on how to fire particular events manually.
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The following article includes more information on how to fire particular events manually.
Regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
John Yu
Top achievements
Rank 1
answered on 02 May 2008, 11:26 AM
Actually the datasource varies between the default binding and binding after the selected indexchanged event
what i mean is based on the selection on the dropdownlist i have to modify the grid data.
I bind by means of needdatasource event of the grid when the grid first loads, and i did paging and sorting based on the needdatasource event,
so i need the datasource to be changed based on the Dropdownlist modification and do paging and sorting on this
Do you understand my requirement
0
Shinu
Top achievements
Rank 2
answered on 02 May 2008, 12:28 PM
Hello,
I tried the following code snippet to achieve the desired scenario on my end.
ASPX:
CS:
Hope this helps..
Shinu.
I tried the following code snippet to achieve the desired scenario on my end.
ASPX:
| <rad:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"> |
| </rad:RadGrid> |
| <br /> |
| <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> |
| <asp:ListItem Text="" ></asp:ListItem> |
| <asp:ListItem Text="Persons" ></asp:ListItem> |
| <asp:ListItem Text="employee" ></asp:ListItem> |
| </asp:DropDownList> |
CS:
| protected void RadGrid1_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) |
| { |
| string connectionstring = "Data Source=inc141.softinc.com; Initial Catalog=MyDataBase;User ID=sa; Password=sa"; |
| SqlConnection conn = new SqlConnection(connectionstring); |
| string strval = DropDownList1.SelectedItem.Text.ToString(); |
| if (strval == "" ) |
| { |
| conn.Open(); |
| SqlDataAdapter adp = new SqlDataAdapter("select * from NewTable", conn); |
| DataTable dt = new DataTable(); |
| adp.Fill(dt); |
| RadGrid1.DataSource = dt; |
| conn.Close(); |
| } |
| else if (strval == "Persons") |
| { |
| conn.Open(); |
| SqlDataAdapter adp = new SqlDataAdapter("select * from Persons", conn); |
| DataTable dt = new DataTable(); |
| adp.Fill(dt); |
| RadGrid1.DataSource = dt; |
| conn.Close(); |
| } |
| else if (strval == "employee") |
| { |
| conn.Open(); |
| SqlDataAdapter adp = new SqlDataAdapter("select * from employee", conn); |
| DataTable dt = new DataTable(); |
| adp.Fill(dt); |
| RadGrid1.DataSource = dt; |
| conn.Close(); |
| } |
| } |
| protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| RadGrid1.Rebind(); |
| } |
Hope this helps..
Shinu.