Friday, January 25, 2008

SelectableTextBox example ...

A month ago I wrote an entry on the SelectableTextBox custom control. Since the control has been slightly upgraded since then, this time I provide not only the up to date source code of the control itself but also a complete example of its usage.

The code can be downloaded from here


Nietzky said...

Wiktor this is a great piece of code you wrote... But I need help desperetly. The code you posted uses a dummy list that you generated to populate GridView. I am trying to incorporate your code into my app in EditTemplate of a Formview and I spent a day to figure out how to pass key and value from one page to another using SQLDataSource not ObjectDataSource
Needed to strip the tags, but it goes like this:

SqlDataSource ID="SqlDataSourceState" runat="server" ConnectionString="somestring"
SelectCommand="SELECT DISTINCT PropertyID, Name, Address, City, State FROM RealEstate ORDER BY State

This is my meta for the table:
CREATE TABLE [dbo].[RealEstate](
[PropertyID] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Name] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[City] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[State] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

In my SelectItem.aspx, I incorporated search feature.

The results of the search in the popup page show gridview and come like this:
PropertyID Name Address City STATE
11094 Ralph Building - 732 Main 712 Main Street Houston TX
11151 Houston Club Building 812 Dusk Street Houston TX
I want to pass "11094" or "11151" to textbox in parent page. Then from the InsertTemplate click on button called "insert" and value are passed.

Pomoz bracie! Wciaz ucze sie tego.
Jack or "Jacek"

Nietzky said...

LinkButton ID="SelectButton" runat="server" CommandName="itemselect" CommandArgument=

The Item causes error for me. This is because I am binding to GridView. The question is how to do this with GridView

Wiktor Zychla said...


this refers to the identity of the business object you bind to.

I suspect that you should just replace this with

<%# Eval( "PropertyID" ) %>

because you can directly refer to the identity of the datarow from your datasource.

in case of any further assistance just write an email message to me.

Anonymous said...

Very good article.
Just to extend your control I have created a couple of additions:
1. Ability to show popup up window in the center of client screen. left=(screen.width-width)/2, top=(screen.height-height)/2
2. Ability to filter datagrid dynamically. Put a textbox before the grid and refresh data while typing in textbox using AJAX.

Anonymous said...

Found one more thing...
If item text contains CrLf then Javascript is giving an error message of unterminated string...
to fix it we need to add replace function in ReturnKeyAndValue function:
Script = String.Format(ClientReturnScriptWithSubmit, Page.Request.QueryString("keyControlID"), Key.Replace(vbNewLine, "\r\n"), Page.Request.QueryString("valueControlID"), Value.Replace(vbNewLine, "\r\n"))

Regards, Russell