DataGrid

xiaoxiao2021-03-06  47

Http://www.blogbus.com/blogbus/blog/index.php?blogid=8085

In .net

Love the programming and life!

<<< About the CLOSE and Open of SqlConnection objects in ADO.NET |

Home |

Edit DataGrid Control (1) >>>

DataGrid Usage - Show Boolean, Display Image 2004-02-23

The Boolean field can have two values: True or False. Although it is very simple, there is no unique graphic representation. If you don't want to use text to represent the Boolean field in DataGrid, you can use the checkbox instead, so it is more intuitive. Let's take a column in the Employees table in the SQL Server2000 Northwind database, the Employees table has a column of ReportSto, which contains the numeric value indicating that an employee wants to report to someone. In particular, this field value is the employee number of the superior, if the employee does not report to anyone, it is null.

Boolean.aspx (where DataGrid is set below): < ItemTemplate> <% # databinder.eval (Container.DataItem, "TitleOfCourtesy") "," "" DataBinder.eval (Container.DataItem, "firstname") "" DataBinder. eval (Container.DataItem, "LastName")%> < ask: Checkbox Runat = Server Checked = '<% # Hasboss ((int) DataBinder.eval (container.data Item, "BOSS"))%> 'enabled = false /> When you write to the check box, you may be more strange.

There is no BOSS column in the Employees table, but here is binding to BOSS, is it wrong? Oh, here is not wrong, when you look down, you will understand! Some of the code in boolean.aspx.cs is as follows: private void page_load (Object sender, system.eventargs e) {// Place user code here to initialize page if (! Page.ispostback) {onloadData ();}} void onlinedata () {string strconn = "Database = northwind; server = localhost; uid = sa; pwd =;"; sqlConnection myconn = new sqlConnection (strconn); // When I write here, everyone will understand BOSS source column anyway string strsql = "SELECT employeeid, titleofcourtesy, firstname, lastname, title, ISNULL (reportsto, 0) AS boss FROM Employees"; SqlDataAdapter da = new SqlDataAdapter (strsql, myconn); DataSet ds = new DataSet (); Da.fill (DS, "MyTable"); grid.datasource = ds.tables ["myTable"]; grid.database ();} public bool Hasboss (int bosSID) {if (bossid == 0) Return False; Return True;} Run now, let's take a look at the effect: Yes, it is very intuitive, in order not to let users handle the modification check box, we have set the check box attribute enable to false, no wonder here The options that look will be gray. If you are a very picky person, you will be very dissatisfied with the effect of gray check boxes, right, this effect is honest, and the overall style of the interface is not completely unified and enemied, then we need to do it? Modifications can be made with the interface style? This will be improved by the image.

Images.aspx (DataGrid in part): <% # dataBinder.eval (Container.DataItem, "TitleOfcourtesy" "," "" DataBinder.eval (Container). DataItem, "LastName") "" DataBinder.Eval (Container.DataItem, "FirstName")%> <

/ ask: DataGrid> images.aspx.cs: Binding and binding of DataGrid in binding and boolean.aspx.cs, different parts are getPropertygiffile function sections: public string getPropeGiffile (int bosSID) {if (bossid == 0) Return "images / unchecked.gif"; return "images / checked.gif";} After doing the above steps, let's take a look at the effect! PAIRS Posted at 2004-02-23 15:03 Quote Trackback (0) | Edit

Comments

Comment

Recent Update For Three-layer Structure Configuration About 3 Text Editing DataGrid Control (2) Editing DataGrid Controls (1) DataGrid Using - Color Scheme DataGrid Using - Show Boolean Values, Display Image CLOSE and Open ASP in ADO.NET Classic example of .NET commonly used (1) DataList appearance with JavaScript to write the same day

转载请注明原文地址:https://www.9cbs.com/read-75549.html

New Post(0)