ASP.NET - Use a checkbox to change the results of a SqlDataSource - asp.net

I'm using Visual Web Developer 2010 Express. This is my first attempt at creating a .NET page. I have a Gridview on a page that displays the results of a GridQuery. This works. I have a checkbox control (cb_Filter) on the same page that if checked, should add to the where clause of the GridQuery, (where Column5 IS NULL). How do I check the state of the check box so it will run the query with or without the "filter".

really depends on your data access, if you have made a datasource on page, then you'll have two and the code will change which data source you have. if it is using the old ado.net then you will have two commands that run in seperate methods that get the sql query, and a similar thing will work for linq. Let me know how you bind to the grid and i will give you an example.

If you want the grid results to change dynamically, autopostback should be True for the checkbox. This will cause the page to reload when the value changes. Then, in your page load routine you do something like this:
If cb_filter.Checked Then
'set the checked datasource or SQL string here
Else
'set the unchecked datasource or SQL string here
End If

Related

Access imagebutton src in postback

Environment: Microsoft Visual Studio 2019 Community, ASP.NET v4.8 web application project using VB.NET
Problem: I have an asp imagebutton which is used to indicate a status by changing the image each time it is clicked (red-amber-green-red). This is done using javascript:
btn.src = newImage;
This works fine. The imageurl is accessed using src in the html but the image is initially set in the code behind databind by setting the imagebutton.imageurl:
btn.ImageUrl = initialImage
On a postback (a save) I want to find the status by looking at the current imageurl.
Dim btn As ImageButton = CType(mainGrid.Rows(i).FindControl("btn"), ImageButton))
someval = btn.imageurl
The problem is that imageurl shows the value initially set, not the changed value. This weirdness seems to point to a bug in my code somewhere as obviously the imagebutton variable in the save code behind knows nothing about the imagebutton variable in the databind code behind.
Can someone confirm that imageurl in the postback should in fact match the changed src in the html?
Edit: I should say that I don't want to use server-side processing each time they click the imagebutton. I can make this work using a command argument BUT that leads to a database write every time they click. There are a dozen or so buttons on each row so I think that would be pretty slow in production.
The answer, provided by Albert D. Kallal, is that imagebuttons don't pass any changed attributes back to the code behind. Possible solutions are to 1) use an update panel, 2) change a paired hidden field at the same time (of a type that does pass the change back) or 3) use ajax to update the db after the change. I used option 3.

Problem With Multiple Data Bindings (Silverlight)

I am using silverlight to create an Intranet for managing chemical usage. All data is stored in a MS SQL database, and is retrieved by using a DomainService (RIA).
By dragging the database onto the form, Silverlight has created a DomainDataSource based on this table. By then creating a new record using the following code, I am now able to add new records.
Me.ChemicalApplicationDomainDataSource.DataView.Add(chemicalApplication)
However one of the controls I have on the screen is an AutoCompleteBox. I have bound this to the database, and the values display fine on here. When an item is selected on here, I want to populate the value of a textbox with values retrieved from a second datatable.
I have created an event on the AutoSelectedItemChanged, and added the following code:
Context.Load(Context.GetChemicalByNameQuery(AutoMaterialTradeName.Text))
I can then bind this to a datagrid.ItemsSource, and it shows the relevent record. But I cannot for the life of me get it to bind to a textbox. Textboxes dont have an ItemsSource, only a DataContext, but binding to this does not seem to display anything..
Any tips on how to achieve this?
You would need to bind it to the Text property on the TextBox for that to work. Additionally you would probably need to set the Path property on the binding to get the right property on your object to display.

How to develop a Query Analyzer

I want to develop the application in which user write query into the text box when it click on the submit button it displays the results in the Grid just just in the Sql Server query analyzer tool i used VS 2008 and application develop in Asp.Net using C#.
Thanks
It depends on how advanced you want to have it. Most scenarios suffice with a single textbox in which the sql statement can be written, a button to submit it and a GridView control with AutoGenerateColumns="true" (the default) to display the requested data. In the codebehind you simply take the string from the textbox, use it as inline sql statement and use simple ADO.NET to connect with the database and bind the result to the GridView.

ASP.NET Gridview Updating Capabilities

The Gridview control in ASP.NET provides updating capabilities when assigning a SqlDataSource control to the Gridview's DataSourceID, however when programmatically assigning a code level SqlDataSource to DataSource, the built-in updating capabilities go away and you are forced to roll your own. Why? What is the difference here, since all we're doing is referring to the SqlDataSource directly, instead of by ID? Why can the GridView still not take advantage of the SqlDataSource UpdateCommand?
Well, the first case, it has 2 native controls. Web and Data. You can perform RAD via VS.NET via their visual and configuration tools. MS ensure that the framework can allow such visual controls to data controls coupling in the aspect of CRUD automatically.
Second case, when you have your own SqlDataSource which is not one of the data controls, you are on your own. That's how it is. I hope someone can tell us a solution for it too.
my 2 cents.
I've discovered that it's possible to programmatically create a SqlDataSource, give it an ID, and assign the properties as follows to allow the built in editing to be mapped properly:
gvData.DataSourceID = dataSource.ID

listview of ASP.NET(web application)

i have placed four textbox inside the listview of web application. if i enter data in first textbox, its corresponding record should be fetched from oracle database and fetched record should be placed in 2,3,4 textbox.
****TextBox.TextChanged Event
How to: Respond to Changes in a TextBox Web Server Control
Edit:
From your edit it would be better to use AJAX.
You can fetch data from oracle database from C# using the AJAX call and return the result to the response and display the data.
If you're using webforms you could use a WebMethod to invoke the query from javascript, you can see an example here.
You could also just add a control that invokes a function server side and use the FindControl method of the ListView to obtain the value of your textbox. Also if you want the function/method to be called when the user stops typing you could use a jQuery plugin called typewatch you can find it here. Also taking into account the WebMethod* attribute that I mentioned earlier in the answer.
Go through the article Complete ListView in ASP.NET 3.5. This article shows how to place textboxes inside listview and edit the data in listview.
For Oracle connection in ASP.NET this article Connecting to an Oracle Database Using ASP.NET—A Step-by-Step Tutorial will definitly helps you

Resources