In Windows ApplicationsProgramYou can use the date control to select a date instead of entering it directly. The advantage is that the date format is not incorrect and the interface is friendly. For example, I need to enter a unit encoding in the input box, but the unit encoding is hard to remember and needs to be queried. This is also easy to implement in winform. In webform, follow the winform implementation method: open a new window, query the results in the new window, select the record row, and return the results to the corresponding input box in the parent window.
Interface for entering data (parent window ):Inputdata. aspx
< ASP: textbox ID = "Txtdepartid" Runat = "Server" > </ ASP: textbox >
< A Href = "Javascript: linkfind_window = Window. Open ('getdepart. aspx? Controlname =Form1.txtdepartid', 'Linkfind _ Window', 'width = 500, Height = 500 '); linkfind_1_focus ()" > Select </ A >
The page for the new window to be opened is getpai.aspx, and the page for deleting is controlname1_form1.txt departid. form1 is the form name (ID) in inputdata. aspx, and txtdepartid is the ID of the input box control.
Subpage: getdepart. aspx
On this page, use the DataGrid or datalist to list all unit codes and unit names, so that the operator can be very clear and click the corresponding row with the mouse, return the encoding of the selected unit to the parent page inputdata. in the txtdepartid of the aspx control.
In fact, it is very easy to return the value to the parent page. The syntax is as follows:
Javascript: window. opener.Form1.txtdepartid. Value = '2014-0401 ';
It is used to assign '2014-0401 'to the input box txtdepartid of the parent window.
I believe that you are familiar with the syntax for passing values in the two windows of the browser. The problem is that you need to add corresponding lines to the DataGrid OF THE subwindow.CodeSo that you can click the corresponding row to return the corresponding value in the row to the parent page, and close the page itself. To make the selected data more vivid, you can add the row background color effect.
The following is the final HTML code for display:
< Tr Onmouseover = "This. style. backgroundcolor = '# cccccccc '" Onmouseout = "This. style. backgroundcolor = 'white '" Onclick = "Javascript: window. opener.Form1.txtdepartid. Value = '2014-0401 '; window. Close ();" >
< TD > 0401-203 </ TD > < TD > Test unit name 1 </ TD >
</ Tr >
We can see that we have added the dynamic effect of background color change, but the most important thing is to generate the onclick code.ArticleIn user operation "OK", we introduced how to add JavaScript code for the control in cells in the DataGrid. Here we can learn from it, but the difference is:
1. Add JavaScript code for each row of the DataGrid, instead of Cell
2. You need to obtain the cell (0) value for each row of the DataGrid.
I directly used the previous code for modification. The Code is as follows:
{
This. style. Display = 'none'; codehighlighter%16_855_open_text.style.display = 'none'; codehighlighter%16_855_closed_image.style.display = 'inline'; inline = 'inline ';
} "Src ="/images/outliningindicators/expandedblockstart.gif "align =" TOP "> {
This. style. Display = 'none'; usage = 'none'; codehighlighter=16_855_open_image.style.display = 'inline'; codehighlighter=16_855_open_text.style.display = 'inline ';
} "Src ="/images/outliningindicators/contractedblock.gif "align =" TOP "style =" display: none "> Private Sub dgdepartment_itemcreated () Sub Dgdepartment_itemcreated ( Byval Sender As Object , Byval E As System. Web. UI. webcontrols. datagriditemeventargs) Handles Dgdepartment. itemdatabound
Dim DGI As Datagriditem = E. Item
Dim Strurl As New Stringbuilder ( 64 )
If (DGI. itemtype = Listitemtype. Item Orelse DGI. itemtype = Listitemtype. alternatingitem) Then
' In this example, only the row item and alternatingitem of the DataGrid are checked.
DGI. Attributes. Add ( " Onmouseover " , " This. style. backgroundcolor = '# cccccc' " )
DGI. Attributes. Add ( " Onmouseout " , " This. style. backgroundcolor = 'white' " )
DGI. Attributes. Add ( " Onclick " , Strurl. append ( " Javascript: window. opener. " ). Append ("form1.txtdepartid" ). Append ( " . Value =' " ). Append (DGI. cells ( 0 ). Text). append ( " '; Window. Close (); " ). Tostring)
End If
End sub
In actual operation, the code shown above is generated for each row of the DataGrid, but the value is empty, instead of the unit code in cells (0, the tracing program finds that in the itemcreated event of the DataGrid, only cells (I) after each itemcreated event occurs ). text has a value, but there is no value when an event occurs. It seems that the required value can be obtained only when other events occur. Check the event list of the DataGrid and find the itemdatabound event. Move the code to the event. Everything works. The final code is as follows:
{
This. style. Display = 'none'; codehighlighter%16_855_open_text.style.display = 'none'; codehighlighter%16_855_closed_image.style.display = 'inline'; inline = 'inline ';
} "Src ="/images/outliningindicators/expandedblockstart.gif "align =" TOP "> {
This. style. Display = 'none'; usage = 'none'; codehighlighter=16_855_open_image.style.display = 'inline'; codehighlighter=16_855_open_text.style.display = 'inline ';
} "Src ="/images/outliningindicators/contractedblock.gif "align =" TOP "style =" display: none "> Private Sub dgdepartment_itemdatabound () Sub Dgdepartment_itemdatabound ( Byval Sender As Object , Byval E As System. Web. UI. webcontrols. datagriditemeventargs) Handles Dgdepartment. itemdatabound
Dim DGI As Datagriditem = E. Item
Dim Strurl As New Stringbuilder ( 64 )
If (DGI. itemtype = Listitemtype. Item Orelse DGI. itemtype = Listitemtype. alternatingitem) Then
' In this example, only the row item and alternatingitem of the DataGrid are checked.
DGI. Attributes. Add ( " Onmouseover " , " This. style. backgroundcolor = '# f1f5e1' " )
DGI. Attributes. Add ( " Onmouseout " , " This. style. backgroundcolor = 'white' " )
DGI. Attributes. Add ( " Onclick " , Strurl. append ( " Javascript: window. opener. " ). Append (convert. tostring (viewstate ( " Formcontrol " ). Append ( " . Value =' " ). Append (DGI. cells ( 0 ). Text). append ( " '; Window. Close (); " ). Tostring)
End If
End sub