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() {
} =============================================================================== 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>
|
thanks to all