Hi there is a RadComboBox inside EditItemTemplate of RadGrid along with a Button.
I am using _ItemsRequested event just to do the search in RadComboBox but not loading the whole list into it on click of RadComboBox.
Current functionality is:
When user click on textarea of RadComboBox, type/key-in any thing, then only the Combo binds the searched related Items into it.
Now I want to get below functionality on button click:
when user click on textarea of RadComboBox, type/key-in any thing, and click on button..then only the Combo shall bind the searched related Items into it.
Please someone reply how to achieve it ?
Below is code of my Current functionality:
<
telerik:RadGrid
ID
=
"RGGSTAcCode"
runat
=
"server"
ShowFooter
=
"True"
GroupingEnabled
=
"False"
ShowStatusBar
=
"true"
EmptyDataText
=
"No record available."
AllowAutomaticInserts
=
"False"
AllowAutomaticUpdates
=
"False"
AllowAutomaticDeletes
=
"true"
OnNeedDataSource
=
"RGGSTAcCode_NeedDataSource"
OnItemDataBound
=
"RGGSTAcCode_ItemDataBound"
OnInsertCommand
=
"RGGSTAcCode_InsertCommand"
OnDeleteCommand
=
"RGGSTAcCode_DeleteCommand"
OnUpdateCommand
=
"RGGSTAcCode_UpdateCommand"
OnItemCommand
=
"RGGSTAcCode_ItemCommand"
>
<
mastertableview
ShowHeadersWhenNoRecords
=
"true"
autogeneratecolumns
=
"false"
datakeynames
=
"AccountCodeID"
InsertItemDisplay
=
"Top"
insertitempageindexaction
=
"ShowItemOnCurrentPage"
ShowFooter
=
"True"
CommandItemDisplay
=
"Top"
ClientIDMode
=
"Static"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
></
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"AccountCodeID"
HeaderText
=
"AccountCode ID"
UniqueName
=
"AccountCodeID"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"AccountCode"
HeaderText
=
"Account Code"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblAcCode"
runat
=
"server"
Text='<%# Eval("AccountCode")%>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:Label
ID
=
"lblAcCode2"
runat
=
"server"
Text='<%# Eval("AccountCode") + " - " + Eval("AccountDescription")%>' Visible="false"></
asp:Label
>
<
telerik:RadComboBox
ID
=
"ddlAccountCode"
runat
=
"server"
Height
=
"200"
Width
=
"240"
DropDownWidth
=
"310"
HighlightTemplatedItems
=
"true"
CausesValidation
=
"true"
OnItemsRequested
=
"ddlAccountCode_ItemsRequested"
EnableItemCaching
=
"true"
ShowDropDownOnTextboxClick
=
"false"
EnableLoadOnDemand
=
"True"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
MarkFirstMatch
=
"True"
Filter
=
"Contains"
AppendDataBoundItems
=
"true"
DataTextField
=
"AccountDescription"
DataValueField
=
"AccountCodeID"
>
</
telerik:RadComboBox
>
<
asp:Button
ID
=
"btnSearch"
runat
=
"server"
Text
=
"Search"
OnClick
=
"btnSearch_Click"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
ConfirmTextFormatString
=
"Are you sure you want to Delete {0} Account Code?"
ConfirmTextFields
=
"AccountCodeID"
ConfirmDialogType
=
"RadWindow"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
></
telerik:GridButtonColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
ButtonType
=
"ImageButton"
/>
</
EditFormSettings
>
<
CommandItemSettings
AddNewRecordText
=
"Add new record"
RefreshText
=
"Refresh"
></
CommandItemSettings
>
</
mastertableview
>
</
telerik:RadGrid
>
public
DataTable GetAccCode(
string
CompanyCode)
{
SqlConnection con =
new
SqlConnection(strcon);
SqlCommand cmd =
new
SqlCommand(
"[Invoice].[usp_tbl_AccountCode_DL_Test]"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@CompanyCode"
, CompanyCode);
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
try
{
con.Open();
da.Fill(dt);
con.Close();
}
catch
(Exception ex)
{
}
return
dt;
}
#region Load on Demand
private
const
int
ItemsPerRequest = 50;
private
static
string
GetStatusMessage(
int
offset,
int
total)
{
if
(total <= 0)
{
return
"No matches"
;
}
else
{
return
String.Format(
"Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>"
, offset, total);
}
}
protected
void
ddlAccountCode_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
//Allow only search in RadComboBox, do not load whole List item initially on combobox click
RadComboBox combo = (RadComboBox)sender;
string
c = ddlCompany.SelectedValue.ToString();
DataTable dt =
new
DataTable();
string
txt = e.Text;
int
itemOffset=0;
int
endOffset=0;
if
(txt == String.Empty)
{
combo.ShowDropDownOnTextboxClick =
false
;
}
else
{
dt = GetAccCode(c);
//got all Items related to selcted company in dt
DataView dv =
new
DataView(dt);
dv.RowFilter =
string
.Format(
"AccountDescription LIKE '%{0}%'"
, txt);
dt = dv.ToTable();
int
a = dv.Count;
//get the filtered/searched items
if
(dv.Count > 0)
{
itemOffset = e.NumberOfItems;
endOffset = Math.Min(itemOffset + ItemsPerRequest, dt.Rows.Count);
e.EndOfItems = endOffset == dt.Rows.Count;
}
else
if
(a <= 0)
{
itemOffset = e.NumberOfItems;
endOffset = Math.Min(a, a);
e.EndOfItems = endOffset == a;
}
}
//code adds/bind the records inside Combo
for
(
int
i = itemOffset; i < endOffset; i++)
{
combo.Items.Add(
new
RadComboBoxItem(dt.Rows[i][
"AccountDescription"
].ToString(), dt.Rows[i][
"AccountDescription"
].ToString()));
}
//If search/key-in text is not empty, show only searched records no. in footer of Combo
if
(!
string
.IsNullOrEmpty(e.Text))
{
DataView dv =
new
DataView(dt);
int
num = dv.Count;
endOffset = dv.Count;
}
else
{
combo.ShowDropDownOnTextboxClick =
false
;
}
e.Message = GetStatusMessage(endOffset, dt.Rows.Count);
}
#endregion
protected
void
btnSearch_Click(
object
sender, EventArgs e)
{
}