Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databinding using designer 1

Status
Not open for further replies.

NerdTop72

Programmer
Mar 14, 2005
117
US
I have a search button to apply the search variables for text boxes and dropdownlists & textboxes.

I have an original posting in the VB.net 2005 forum here...

upon clicking the search button...
Protected Sub btnSearch_Click
SqlSearchErrors.DataBind()
end sub

This does not update my Gridview1 with the results?

In the designer I have tested my query and it does give me results.

to test out my dropdownlist values I re did my sql statement to only bind to my dropdownlist. which displays my values in the gridview upon loading the page. not by the search button click event.

How do I invoke the bind for the text box values by using my button click control? I mean, what is the point of the designer bind fields if it will not take the textbox values upon a request? I know I am missing something simple here.

Shouldn't the designer know to bind with the text box controls automatically and update my gridview just like changing the selected item in the dropdownlist would update the gridview?

Thanks
 
Could you be a little more clear in what you want to do? You also need to post more of the code. What version of the framework are you using?
 
I am using .net 2.0

I want to be able to show search results via a button click based on 1 Dropdownlist and 3 textboxes
DDLSoftwareID
txterrordescription
txtErrorcode
txteventid

I do not want to have all my fields to have to be searched for all the time

For instance,
DDLSoftwareID = "adobe"
txterrordescription = "loading"
txterrorcode = <nothing>
txtevenid = <nothing>

Here is my SQL statement that I wrote via the designer. I also bound my TXTbox & Dropdownlist as controls using the where button in the designer for my sqlDataSource.

SELECT * FROM [TBLError] WHERE (([SoftwareID] = @SoftwareID) or ([ErrorDescription] LIKE '%' + @ErrorDescription + '%') or ([ErrorCode] = @ErrorCode) or ([EventID] = @EventID))

I have changed my button click event from the previous post to this...
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Me.GridView1.DataBind()
End Sub

I think my problem is somewhere in my SQL statement. I do not know how to search 1, 2, 3, or 4 fields at a time. I just tried to use this query 1 dropdownlist and 1 text field
SELECT * FROM [TBLError] WHERE (([SoftwareID] = @SoftwareID) and ([ErrorDescription] = @ErrorDescription))

Filling in both the dropdownlist and the description text box returned exact results.

When I change the “and” to an “or” with the same statement, and only choose a dropdownlist item and searched, no results. When I entered only an error description and searched, no results. When I entered both, results are returned in the gridview. I want it to work with 1 or the other fields (actually all 4 fields) but still return results if 1 box is filled in as opposed to know exactly what I am searching for.

I will wait for a response before I start searching the SQL Statement forum.

Sorry for my confusing explanation :) I really hope this makes sense
Thanks
 
Thanks ca8msm, you post led me to Optional parameters which in turn led me to this sql command COALESCE

this is how I am using it to test just 2 of my fields.
SELECT SoftwareID, ErrorDescription, EventID, ErrorCode, Solution
FROM TBLError
WHERE (ErrorDescription = COALESCE (@ErrorDescription, ErrorDescription)) OR
(SoftwareID = COALESCE (@SoftwareID, SoftwareID))

For some reason I still do not get the results I want in my gridview. I do, however, get the results I am looking for in both SqlServer Query Builder and the VS.NET Query Builder. But when I run my page it does not fill my gridview based on my SoftwareID Dropdownlist. I have to have both SoftwareID choosen and data filled in my textbox for the ErrorDescription to fill the gridview??

Thanks for the lead!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top