Remember to introduce the header file using system. Data. sqlclient
First, let's look at the form programming, using the datagridview, bingingsource and dataset. First of all, we need to get dataset ..
For example, sqlconnection con = new sqlconnection (... omitted here); then sqladapter adapter = new sqladpter ("SELECT statement", Conn );
Dataset DATA = new dataset ();
Adapter. Fill (data); there are multiple kinds of overloading in this place. You can give the returned table a corresponding name to facilitate the index.
For example, Adapter. Fill (data, "userinfo ");
Data. Tables ["userinfo"] is the table. Otherwise, you need to use a digital index. Data. Tables [0], of course, this order is related to the order of your fill, you know.
Next, let's take a look at the bingingsource settings.
This is a drag-and-write control. The datasource is a dataset, and datamember is one of the tables.
Finally, let's look at the binding of the datagridview and bind the bingingsource and the datagridview directly.
Finally, let's take a look at
Set the bingingsource filter.
In fact, the most important thing is filter settings .. This is a fuzzy search.
Then let's look at the filtering of Asp.net gridview.
Required empty items: sqldatasource and gridview.
First, check the front-end
<Asp: sqldatasource id = "sqldatasource1" runat = "server"
Connectionstring = "<% $ connectionstrings: connectionstring %>"
Filterexpression = "course No. Like '{0} %' or course name like '{0} % '"
Providername = "<% $ connectionstrings: connectionstring. providername %>"
Selectcommand = "select CNO 'course No. ', cname 'course name', cpno 'pre-course No.', ccredit 'credits ', chour 'hours ', cterm 'open semesters 'from course ">
<Filterparameters>
<Asp: controlparameter controlid = "textbox1" name = "newparameter"
Propertyname = "text"/>
</Filterparameters>
</ASP: sqldatasource>
<Asp: gridview id = "gridview1" runat = "server" performanceid = "sqlperformance1">
</ASP: gridview>
<Asp: Label id = "label1" runat = "server" text = "query"> </ASP: Label>
<Asp: textbox id = "textbox1" runat = "server" ontextchanged = "textbox#textchanged"
Autopostback = "true"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
</Form>
Similar to form programming. Sqldatasource sets the connection string. And select statements. Then bind it with the gridview
These attributes can be written by hand or directly. The important thing is how to implement filtering.
The main thing is the following... For beginners, it is recommended to directly modify the attribute generation. I am also a beginner, but I am helpless. The teacher of tiankeng needs to set up a course ..
Filterexpression = "course No. Like '{0} %' or course name like '{0} % '"
<Filterparameters>
<Asp: controlparameter controlid = "textbox1" name = "newparameter"
Propertyname = "text"/>
</Filterparameters>
{0} is a placeholder, which is similar to that in string. format. Because I want to find the course number or name in a Textbox, it is written like this.
Then enable autopostback in Textbox, and add two events: textbox1_textchanged and button#click to achieve the same effect as form retrieval.
The function of enabling automatic sending back is to automatically send the event back to the server as long as the event occurs. Otherwise, you need to double-click the button to return the result.
There is no real-time effect.