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

[Solved] radgrid

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 03 Aug 2009, 01:45 AM
Hi,

Can anyone tell me how to repopulate the grid based on dropdownlist selction changed. this dropdown is not part of grid.
 
It's a separate control by itself in the ascx. so, when i change values in this dropdown, my radgrid should bring corresponding values and bind to the radgrid. is it possible.
how do i implement this(c#).

Also, can someone tell when the grid's itemdataboud event will get called. To get this event called should i have radgrid.databind() ???
So, the radgrid should be filled first prior to calling this event right???
Thanks,
ZR

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Aug 2009, 06:23 AM
Hi Zaheka,

I guess the DropDownlist is in the UserControl which is placed on the aspx page which contains RadGrid and hence you need to populate the Grid on changing the values in the DropDownList. If so you may give a try with the following approach.

ASPX:
 
<telerik:RadGrid ID="RadGrid1" runat="server"  AllowPaging="true" PageSize="5"  AutoGenerateColumns="true" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource"
            <MasterTableView  Name="MasterTable"  > 
            </MasterTableView> 
        </telerik:RadGrid><br /> 
        <br /> 
        <uc1:WebUserControl ID="WebUserControl1" runat="server" /> 

ASCX:
 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" 
    Inherits="WebUserControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" 
    Width="191px"
     <asp:ListItem Text="Orders" ></asp:ListItem> 
      <asp:ListItem Text="Products" ></asp:ListItem> 
</asp:DropDownList> 
 


ASCX.CS:
 
 public delegate void  SelectionChanged(string DataSource); 
    public event SelectionChanged selectionHandler;  
    
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
         
    } 
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        string DataSource = DropDownList1.SelectedItem.Text; 
        if (selectionHandler != null
            selectionHandler(DataSource); 
         
    } 


ASPX.CS
 
 protected void Page_Load(object sender, EventArgs e) 
    { 
 
        WebUserControl1.selectionHandler += new WebUserControl.SelectionChanged(WebUserControl1_selectionHandler);     
     
    } 
 
    void WebUserControl1_selectionHandler(string DataSource) 
    { 
         
        BindGrid(DataSource); 
        RadGrid1.Rebind(); 
    } 
 
 protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            string CurrentDataSource = "Products"
            BindGrid(CurrentDataSource); 
        } 
    } 
 
    private void BindGrid(string CurrentDataSource) 
    { 
        string connectionstring = "Data Source=inc156; Initial Catalog=NorthWind;User ID=sa; Password=mypassword"
        SqlConnection conn = new SqlConnection(connectionstring); 
        conn.Open(); 
        SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM "+ CurrentDataSource, conn); 
        DataSet ds = new DataSet(); 
        adp.Fill(ds); 
        RadGrid1.DataSource = ds; 
 
        conn.Close(); 
    } 


You may go through the following help article to get more details Event sequence of RadGrid.
Event sequence

Regards
Shinu
Tags
Grid
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or