I want to fetch value from dropdownlist when selected. On that selection of value I am firing a simple select query ie.
"select * from Catego开发者_C百科ry where cat_name ='" + dropdownlistselectedvalue + "'"
here is the code of needDatasource
protected void rdgridview_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { if (!e.IsFromDetailTable) {
//I want to fetch the dropdownlist selected value here ie string dpvalue = DropDownList1.SelectedValue.ToString();
string strqry = "select * from Categories where Category_Name = '"+ dpvalue +"'";
rdgridview.DataSource = getDataTable(strqry);
}
}
But I am not able to fetch the value from the dropdownlist selected value in needDatasource method. How shall I fetch the value or fire any event of dropdownlist control?
Thanks in advance
Telerik has a detailed documentation. You might want to try simple data binding. Check it here. For NeedsDataSource documentation, check here.
You can do that easily by saving the dropdownlist selected value in a ViewState
, do that in the SelectedIndexChanged
event for the dropdownlist .
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["List1_Value"] = DropDownList1.SelectedValue.ToString();
}
then get the value from ViewState
in the needDatasource
event:
string strqry = "select * from Categories where Category_Name = '" + ViewState["List1_Value"]+ "'";
精彩评论