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

[Solved] Grid Telerik ver.2009

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jols
Top achievements
Rank 2
Jols asked on 12 May 2009, 05:53 AM
 hello to all expert on telerik,

                good day to all ! I installed telerik ver.2009 coz i found some new features that could cater my filtering, i followed the sample on the web, about embedding radcomboxbox as my filtering inside the grid and its work fine using the sqldatasource..but we advice not to use a sqlinjection, we advice to used a stored procedure for binding the grid,,how am i going to recode the given sample codes..anyway heres my default.aspx.cs code

SqlConnection

 

Stringcon = new SqlConnection(ConfigurationManager.ConnectionStrings["IBOS.Properties.Settings.ConnString"].ToString());

 


 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        if (RadGrid1.MasterTableView.FilterExpression != string.Empty)  
        {  
            ReloadCombos();  
 
        }  
    }  
    protected void ReloadCombos()  
    {  
        SqldatasourceSqldatasource.SelectCommand = Sqldatasource.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();  
        RadGrid1.MasterTableView.Rebind();  
    }  
=============================================================
 this is my method supposed to used but i wasnt able to use this becuase of the format above
 which is the RadGrid1.MasterTableView.FilterExpression, how can change that to get only the DataFieldValue on the Radcombobox? 
============================================================
    protected void RebindGrid(string key)  
    {  
        SqlDataAdapter ad = new SqlDataAdapter();  
        DataSet ds = new DataSet();  
        SqlCommand cmd = new SqlCommand("spu_CARFILTERING_SAMPLE_SELECT", Stringcon);  
        cmd.CommandType = CommandType.StoredProcedure;  
        Stringcon.Open();  
        cmd.Parameters.Add("@username", SqlDbType.Char, 50).Value = key.Trim();    
        try  
        {  
            ad.SelectCommand = cmd;  
            ad.Fill(ds, "tblMaster05Users");  
 
            this.RadGrid1.DataSource = ds;  
            this.RadGrid1.DataMember = "tblMaster05Users";  
            this.RadGrid1.DataBind();  
 
            Stringcon.Close();  
        }  
        catch (Exception ex)  
        {  
            throw ex;  
        }  
    } 
================================================
my method binding the radcombobox

  protected void bindcombox()
  {
    
        SqlDataAdapter ad = new SqlDataAdapter();  
        DataSet ds = new DataSet();  
        SqlCommand cmd = new SqlCommand("spu_CARFILTERING_SAMPLE_SELECT", Stringcon);  
        cmd.CommandType = CommandType.StoredProcedure;  
        Stringcon.Open();  
      
        try  
        {  
            ad.SelectCommand = cmd;  
            ad.Fill(ds, "tblMaster05Users");  
            this.Radcombox1.DataSource =ds;
            this.Radcombox1.DataTextField"fcUserName";  
            this.Radcombox1.DataValueField = "fxKeyID";  
            this.Radcombox1.DataBind();  
 
            Stringcon.Close();  
        }  
        catch (Exception ex)  
        {  
            throw ex;  
        }  

  
  }
===============================================================================
below is my default.aspx where i use sqldatasource following the example..but how can i bind the radcombobox
as a filtertemplate inside the grid using the way i codes above "bindcombox()"?  
================================================================================

<

 

telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"

 

 

Skin="Web20" Width="344px" AllowFilteringByColumn="True" OnPreRender="RadGrid1_PreRender" OnItemDataBound="RadGrid1_ItemDataBound">

 

 

<MasterTableView DataKeyNames ="fcUserName">

 

 

<Columns>

 

 

<telerik:GridBoundColumn HeaderText="UserID" UniqueName="UserID" DataField="fxKeyID" AllowFiltering ="false" >

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn HeaderText="Username" UniqueName="Username" DataField="fcUserName" AllowFiltering ="false" >

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField ="fcUserName" HeaderText ="Combo" UniqueName="Upload">

 

 

<FilterTemplate>

 

 

<telerik:RadComboBox runat ="server" ID ="Radcombo" OnClientSelectedIndexChanged="ComboIndexChanged"

 

 

AppendDataBoundItems="true" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Upload").CurrentFilterValue %>'

 

 

DataTextField ="fcUserName" DataValueField ="fcUserName" DataSourceID ="Sqldatasource">

 

 

<Items>

 

 

<telerik:RadComboBoxItem Text ="All" />

 

 

</Items>

 

 

</telerik:RadComboBox>

 

 

<telerik:RadScriptBlock ID ="RadScriptBlock1" runat="server">

 

 

<script type="text/javascript">

 

 

function ComboIndexChanged(sender,args)

 

{

 

var tableView=$find("<%#((GridItem)Container).OwnerTableView.ClientID %>");

 

tableView.filter(

"Upload",args.get_item().get_value(),"EqualTo");

 

 

}

 

</script>

 

 

</telerik:RadScriptBlock>

 

 

</FilterTemplate>

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

<%

--SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("UserID").CurrentFilterValue %>'

 

OnClientSelectedIndexChanged="TitleIndexChanged">--

 

%>

 

 

<asp:SqlDataSource ID="Sqldatasource" ConnectionString ="<%$ ConnectionStrings:IBOS.Properties.Settings.ConnString %>"

 

 

ProviderName="System.Data.SqlClient" SelectCommand="SELECT fxKeyID, fcUserName FROM tblMaster05Users"

 

 

runat="server"></asp:SqlDataSource>

 


sample codes is higly appreciated

thanks to all

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 14 May 2009, 01:23 PM
Hello Jols,

In order to achieve your goal you could try using parameters for your stored procedure. Or another way is to filter the dataset returned from the current stored procedure as below:

this.Radcombox1.DataSource =ds.Tables[0].Select(RadGrid1.MasterTableView.FilterExpression); 

Check it out and let me know if this helps.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jols
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Share this question
or