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

[Solved] Accessing RadGrid methods from other nongrid methods

4 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Yu
Top achievements
Rank 1
John Yu asked on 02 May 2008, 10:43 AM
Hi all,
It Would be very helpful if i Know how to access or fire a Radgrid Event for ex:NeedDataSource event from other control events for ex: a dropdown list selectedindexchanged event

Thanks in Advance

4 Answers, 1 is accepted

Sort by
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:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
    {  
        RadGrid1.Rebind();  
    } 


Thanks
Princy.
0
Yavor
Telerik team
answered on 02 May 2008, 11:14 AM
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
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:
 <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.
Tags
Grid
Asked by
John Yu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Yavor
Telerik team
John Yu
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or