HOWTO: Changing SmartDBView current page with a text box
Saturday, 24 November 2007
The current page index of the SmartDBView form can be controlled with a textbox. This can be achieved in two ways - either with a customized SmartPager or directly using the SmartDBView.RowIndex property which is similar to the FormView.PageIndex property.
SUMMARY
The current page index of the SmartDBView form can be controlled with a textbox. This can be achieved in two ways - either with a customized SmartPager or directly using the SmartDBView.RowIndex property which is similar to the FormView.PageIndex property.
MORE INFORMATION
Using SmartPager
You can modify the user interface template of the SmartPager control and put your textbox in it. In addition a button is added which the user should press after he
enters the page number in the text box. - In Design mode, open SmartPager smart-tag panel and select the
Create Numeric Template or Create DropDownTemplate command.
- Select the Edit Templates command and drag-and-drop a textbox and a button control from the toolbox into the PagerTemplate frame.
You can also add an Integer RangeValidator to validate the textbox value.
- In addition set the new button's properties respectively - CausesValidation=false UseSubmitBehavior=false CommandName="Page".
The CommandName="Page"
designates the button as a paging button. The CommandArgument should be
assigned dynamically by using the TextBox's value. You can find more
information about the available command names in the documentation - SmartPager Class
The new mark up will look something like this:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" CausesValidation=false UseSubmitBehavior=false
CommandName="Page" runat="server" OnClick="Button1_Click" Text="Go" />
- Double click the button to create an OnClick event
handler. The event handler have to extract the page number from the
TextBox and set it as a CommandArgument for the button. The code will
look like this:
protected void Button1_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
TextBox txtPageNumber = (TextBox)button.NamingContainer.FindControl("TextBox1");
button.CommandArgument = txtPageNumber.Text;
}
Using SmartDBView.RowIndex
Paging with text box can also be created without using SmartPager. The
SmartDBView.RowIndex property has the same behaviour as the FormView.PageIndex property.
Create a textbox and a button and in the button's OnClick event handler change the SmartDBView.RowIndex value.
Here is a simple example. There is no validation of the user input:
protected void btnPage_Click(object sender, EventArgs e)
{
// RowIndex is zero based
SmartDBView1.RowIndex = Math.Max(0, int.Parse(txtPageNumber.Text) - 1);
}
|