ASP. NET website development and deployment FAQs, asp.net website development
The main content of this article: I. Asp.net project: Precautions for using the Data Control gridview & Xml operations; II. Common Code: some common code analysis; iii. Website deployment: the main process of site deployment; 1. Asp.net Project
Use the asp.net Data Control gridview to display data
The data source adopts xml (the advantage is the structure specification, which facilitates rapid development and bypassing permission control)
The Button uses imgbutton instead of the link Button provided by the gridview, which is beautiful and easy to beautify.
Open the Tool bar editor with VS2010, for example:
1. Add a new webpage
2. Drag the gridview to the page.
3. The previous code is automatically generated.
Open VS2010 and expand Solution to view the file structure:
Main Resources:
1. Images
2. Data
3. Page
4. class files
Ii. Common Code
The HTML code of the GridView control:
Asp: GridView ID = "GridView1" runat = "server">
</Asp: GridView>
Add a Gridview control event and generate background code, such:
The front-end code is as follows:
<Asp: gridView ID = "gv_xml" runat = "server" AutoGenerateColumns = "False" OnRowCancelingEdit = "inline" OnRowUpdating = "inline" OnRowEditing = "inline" OnRowDeleting = "inline" CellPadding = "4 "ForeColor =" #333333 "GridLines =" None "> <Columns> <asp: templateField HeaderText = "Domain Name"> <ItemTemplate> <% # DataBinder. eval (Container. dataItem, "Domain") %> </ItemTemplate> <EditItemTemplate> <asp: TextBox ID = "Txtbox0" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "Domain") %> '> </asp: TextBox> </EditItemTemplate> </asp: TemplateField> <asp: templateField HeaderText = "FAT1"> <ItemTemplate> <% # DataBinder. eval (Container. dataItem, "FAT1") %> </ItemTemplate> <EditItemTemplate> <asp: TextBox ID = "Txtbox1" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "F AT1 ") %> '> </asp: TextBox> </EditItemTemplate> </asp: TemplateField> <asp: templateField HeaderText = "FAT8"> <ItemTemplate> <% # DataBinder. eval (Container. dataItem, "FAT8") %> </ItemTemplate> <EditItemTemplate> <asp: TextBox ID = "Txtbox2" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "FAT8") %> '> </asp: TextBox> </EditItemTemplate> </asp: TemplateField> <asp: TemplateField HeaderText = "FAT21"> <Ite MTemplate> <% # DataBinder. eval (Container. dataItem, "FAT21") %> </ItemTemplate> <EditItemTemplate> <asp: TextBox ID = "Txtbox3" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "FAT21") %> '> </asp: TextBox> </EditItemTemplate> </asp: TemplateField> <asp: templateField HeaderText = "FAT22"> <ItemTemplate> <% # DataBinder. eval (Container. dataItem, "FAT22") %> </ItemTemplate> <EditItemTemplate> <asp: Text Box ID = "Txtbox4" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "FAT22") %> '> </asp: TextBox> </EditItemTemplate> </asp: TemplateField> <asp: templateField HeaderText = "FAT23"> <ItemTemplate> <% # DataBinder. eval (Container. dataItem, "FAT23") %> </ItemTemplate> <EditItemTemplate> <asp: TextBox ID = "Txtbox5" runat = "server" Text = '<% # DataBinder. eval (Container. dataItem, "FAT23") %> '> </asp: TextBox> </ EditItemTemplate> </asp: TemplateField> <ItemTemplate> <asp: ImageButton ID = "Button2" runat = "server" Text = "Edit" ImageUrl = "~ /Imgs/btnEdit.png "CommandName =" Edit "/> <asp: ImageButton ID =" ImageButton1 "runat =" server "ImageUrl = "~ /Imgs/btnDelete.png "CommandName =" Delete "/> </ItemTemplate> <EditItemTemplate> <asp: imageButton ID = "Button1" runat = "server" Text = "Update" ImageUrl = "~ /Imgs/btnUpdate.png "CommandName =" Update "/> <asp: ImageButton ID =" Button3 "runat =" server "Text =" Cancel "ImageUrl = "~ /Imgs/btnCancel.png "CommandName =" Cancel "/> </EditItemTemplate> </asp: templateField> </Columns> <AlternatingRowStyle Wrap = "False" BackColor = "White"/> <EditRowStyle BackColor = "# 2461BF"/> <FooterStyle BackColor = "#507CD1" Font- bold = "True" ForeColor = "White"/> <HeaderStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/> <PagerStyle BackColor = "# 2461BF "ForeColor =" White "HorizontalAlign =" Center "/> <RowStyle BackColor =" # EFF3FB "/> <SelectedRowStyle BackColor =" # D1DDF1 "Font-Bold =" True "ForeColor = "#333333"/> <SortedAscendingCellStyle BackColor = "# F5F7FB"/> <SortedAscendingHeaderStyle BackColor = "#6D95E1"/>
The background code is as follows:
Protected void upload (object sender, cmde) {gv_xml.EditIndex =-1; Databind ();} protected void gv_xml_RowEditing (object sender, GridViewEditEventArgs e) {gv_xml.EditIndex = e. newEditIndex; Databind ();} protected void gv_xml_RowUpdating (object sender, GridViewUpdateEventArgs e) {string Xmlpath = String. format ("{0} \ APIData \ FatEnvData. xml ", RootPath); GridViewRow row = gv_xml.Rows [e. rowIndex]; // get the int numCell = row of the current row. cells. count; // a total of several cells (including the Edit and Delete columns) int currentRow = row. dataItemIndex; // The row index DataSet ds = new DataSet (); ds. readXml (Xmlpath); DataRow dr; dr = ds. tables [0]. rows [row. dataItemIndex]; string [] str = null; // This array defines the table's column name str = new string [] {"Domain", "FAT1", "FAT8 ", "FAT21", "FAT22", "FAT23"}; int j = 0; TextBox myTextBox = null; // starting from column 1st, the last two columns are Edit and Delete for (int I = 0; I <numCell-1; I ++) {myTextBox = row. cells [I]. findControl ("Txtbox" + I) as TextBox; // string cText = (TextBox) row. cells [I]. controls [0]). text; dr [str [j] = myTextBox. text; j ++;} ds. writeXml (Xmlpath); // write the modification to the Table. xml gv_xml.EditIndex =-1; Databind ();} protected void gv_xml_RowDeleting (object sender, GridViewDeleteEventArgs e) {string Xmlpath = String. format ("{0} \ APIData \ FatEnvData. xml ", RootPath); GridViewRow row = this. gv_xml.Rows [e. rowIndex]; int curr = row. rowIndex; DataSet ds = new DataSet (); ds. readXml (Xmlpath); DataRow dr = ds. tables [0]. rows [curr]; dr. delete (); ds. writeXml (Xmlpath); Databind ();}
Data Binding during page loading:
Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) Databind ();} // bind public void Databind () {var query = GetXMLData (); gv_xml.DataSource = query; gv_xml.DataBind ();} // query the private List of xml data <LinqXmlGridViewControl> GetXMLData () {var xDoc = XDocument. load (Server. mapPath ("~ /APIData/FatEnvData. xml "); var query = (from LinqXmlGridViewControl in xDoc. descendants ("Server") select new LinqXmlGridViewControl () {Domain = LinqXmlGridViewControl. element ("Domain "). value, FAT1 = LinqXmlGridViewControl. element ("FAT1 "). value, FAT8 = LinqXmlGridViewControl. element ("FAT8 "). value, FAT21 = LinqXmlGridViewControl. element ("FAT21 "). value, FAT22 = LinqXmlGridViewControl. element ("FAT22 "). value, FAT23 = LinqXmlGridViewControl. element ("FAT23 "). value }). toList (); return query ;}
3. Website deployment
After the code is complete, you need to deploy it in IIS. Open Control Panel> Control Panel project> management tools:
On the website, right-click and choose add website, for example:
The default application pool is. Net4.0. Otherwise, the IIS website cannot be started:
Select the physical path and the local website file storage address. Select the Ip address of the local machine. The default port is 80.
If the host name has a domain name, it can be set. If not, it is null.
Deployment completed
For example, you can change the pool here; specify the path again;
The company currently uses tools for automatic configuration. If there is a problem, you can log on to the server for manual modification (website connection configuration, redirection, database connection string, code version viewing, etc)