473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Search Grid with .NET DataGrid

I have a standard .NET DataGrid that is bound to a DataView. When the user
types into a text box above the DataGrid I issue the following code:

try
{
// We need to search for whatever the user is typing based on the type of
search ...
if (this.txtValue.Text.Length == 0)
{
this.UnHighlightRow();
return;
}

if (this.cbSrhBy.SelectedIndex.Equals(3))
return;

string lcSort = this.SrchFields[cbSrhOn.SelectedIndex].ToString().Trim(),
lcValue = this.ConvertValue(this.txtValue.Text.Trim());
DataRow[] laRows = null;

switch (this.cbSrhBy.SelectedIndex)
{
case 0: // Start of Field
if (lcValue.IndexOf("'").Equals(-1))
lcValue += "%";
else
lcValue = lcValue.Insert(lcValue.Length - 1, "%");

laRows = this.dsSearch.Tables[0].Select(lcSort + " LIKE " + lcValue,
lcSort);

break;

case 1: // Exact Phrase
laRows = this.dsSearch.Tables[0].Select(lcSort + " = " + lcValue, lcSort);

break;

case 2: // Any Part of Field
if (lcValue.IndexOf("'").Equals(-1))
lcValue = "%" + lcValue + "%";
else
lcValue = lcValue.Insert(lcValue.Length - 1, "%").Insert(1, "%");

laRows = this.dsSearch.Tables[0].Select(lcSort + " LIKE " + lcValue,
lcSort);

break;

case 3: // Filter Results
return;
}

if (laRows == null || laRows.Length.Equals(0))
return;

DataView loView = this.dsSearch.Tables[0].DefaultView;

this.UnHighlightRow();
this.dataGrid_Results.CurrentRowIndex = loView.Find(laRows[0][lcSort]);
this.HighlightRow();

this.txtValue.Focus();
}
catch (Exception loExcep)
{
SharedCode.ErrorMessage(loExcep.ToString());
}

This UnHighlightRow and HighlightRow simply issue Unselect() and Select() on
the CurrentRowIndex.

What happens is when I search on a particular value, like let's say
"Last_Name" and I type in "SMI", it will go to the Smith's but it may not
choose the first one that is shown in the DataGrid when the Find() method is
issued. Why?

Mike
Nov 16 '05 #1
0 1144

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Job Lot | last post by:
My DataGrid is bound to DataSet which contains relationship between two tables as follows: SqlHelper.FillDataset(strConn, CommandType.StoredProcedure, "spSelectClientApplicant", ds, New String()...
3
by: serge calderara | last post by:
Dear all, I am using a datagrid which is populate from an array list items This array list can be updated at anytime.If this occurs I need that the content of the datagrid get synchronise too. ...
2
by: Sriram | last post by:
Hi, i am developing a search page, basically using datagrid. i have given a column as hyperlink so that when the user clicks on it, it gives the details of the selected item in a seperate page....
1
by: Linda | last post by:
Hi, I'm new to asp.net and tryign to learn how to work with data grids. I'm retrieving data from a stored procedure and putting it in a data grid. I then want to be able to sort the data when...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
4
by: Girish | last post by:
Im trying to create a grid within a grid programmatically. Ive been successful in doing this but I need the embedded grid to fire its ItemDataBound event so I can handle it. The event does not seem...
9
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.