Demonstrations > ReQuery demo
ReQuery demo
ReQuery examples
People often ask about the ReQuery functions.
The important thing to remember is this: When the page is delivered
to the browser, a DbCombo has no data (unlike a DropDownList control
where the data is bound on the server and delivered to the browser
inline with the page HTML).
Records are only loaded after text is typed in the textbox, or the
search button is clicked, or a ReQuery is performed.
After a postback, DbCombo will automatically perform a query (with
the same query text that was last performed on the previous page),
and return the same number of results as was last shown. This is
called a ReQuery. This happens directly after the page loads, and
the results stay closed. When you click on the DbCombo, the results
are immediatly opened without the need to query the server.
You can simulate a ReQuery without the need for a postback or actual
input from the user. You should set:
ReQueryOnLoad=true
This instructs DbCombo to do the ReQuery even though the page may
not have been through a postback.
ReQueryText (string)
This is the query that is done. Leave it blank for an empty query
e.g. to simulate the a click of the search button.
ReQueryRecords (int)
This is the number of records to return - you don't need to specify
this - the default will be used if it is omitted.
The Text and Value properties of the DbCombo are used to select an item
from the results after a ReQuery is performed. However, be aware that
the item will only be selected if it is in the first page of results.
<table>
<tr>
<td valign=top>
<DbCombo:DbCombo
Runat=server
ID="Dbcombo1"
DropDownRows=20 />
</td>
<td valign=top>
<asp:Button Runat=server OnClick=ButtonClick Text="Postback"/><br>
Text property: <asp:Label Runat=server ID="LabelText" /><br>
Value property: <asp:Label Runat=server ID="LabelValue" /><br>
Re-querying with: <asp:Label Runat=server ID="LabelQuery" /><br>
Re-displaying <asp:Label Runat=server ID="LabelRecords" /> records
</td>
</tr>
</table>
<script runat=server>
protected void ButtonClick(object o, EventArgs e)
{
LabelText.Text=Combo1.Text;
LabelValue.Text=Combo1.Value;
LabelQuery.Text=Combo1.ReQueryText;
LabelRecords.Text=Combo1.ReQueryRecords.ToString();
}
[Cambro.Web.DbCombo.ResultsMethod(true)]
public static object DbComboMethod(
Cambro.Web.DbCombo.ServerMethodArgs args)
{
SqlConnection conn = new SqlConnection("your-connection-string");
SqlCommand myCommand = new SqlCommand(@"
SELECT TOP "+args.Top+@"
Word,
RTRIM(Word) as DbComboText,
RTRIM(Word) as DbComboValue
FROM tWords
WHERE Word LIKE @Query
ORDER BY Word", conn);
myCommand.Parameters.Add("@Query", args.Query+"%");
myCommand.Connection.Open();
return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
</script>
Demonstrations > ReQuery demo |