Some coordination of DataGrid and DropDownList and custom DataGrid using CSS

Source: Internet
Author: User
Tags eval visual studio
Css|datagrid sometimes we need
(1) In the editing time with the Drop-down box to select, and default to the contents of the database
(2) Use the dropdown box to filter the data
(3) Unified custom DataGrid using CSS
The following code is given:
Data:
Table Dep:depid (identifies primary key), Depname (college name)
Table Stu:stuid (logo primary key), Stuname (student name), Studepid (college id= table Dep.depid)

Front desk:
<%@ Page language= "C #" codebehind= "WebForm28.aspx.cs" autoeventwireup= "false" inherits= "csdn. WebForm28 "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<title>WebForm28</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<link href= "Css.css" rel= "stylesheet" type= "Text/css" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
</HEAD>
<body>
<form id= "Form1" method= "POST" runat= "Server" >
<asp:dropdownlist id= "DropDownList1" runat= "Server" autopostback= "True" ></asp:DropDownList>
<asp:datagrid id= "DATAGRID1" runat= "Server" autogeneratecolumns= "False" cellspacing= "1" borderwidth= "0px"
cellpadding= "5" cssclass= "Border" oneditcommand= "edit" oncancelcommand= "Cancel" onupdatecommand= "Update"
datakeyfield= "Stuid" >
<itemstyle cssclass= "Item" ></ItemStyle>
<Columns>
<asp:templatecolumn headertext= "Name" >
<ItemTemplate>
<%# DataBinder.Eval (Container.DataItem, "Stuname")%>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox id= "name" runat= "Server" text= ' <%# DataBinder.Eval (Container.DataItem, "Stuname")%> ' Width= ' 88px ">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:templatecolumn headertext= "College" >
<ItemTemplate>
<%# DataBinder.Eval (Container.DataItem, "Depname")%>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist id= "DEP" runat= "Server" ></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:editcommandcolumn buttontype= "pushbutton" updatetext= "Update" canceltext= "Cancel" edittext= "edit" ></asp: Editcommandcolumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
Background:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Data.SqlClient;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;

Namespace Csdn
{
<summary>
Summary description of the WEBFORM28.
</summary>
public class WebForm28:System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
if (! IsPostBack)
{
Setbind ();
SetBind2 ();
}
}

protected void Setbind ()
{

SqlConnection conn=new SqlConnection (system.configuration.configurationsettings.appsettings["Conn"));
SqlDataAdapter Da=new SqlDataAdapter ("select * from STU,DEP where stu.studepid=dep.depid", conn);
DataSet ds=new DataSet ();
Da. Fill (ds, "Table1");
This. Datagrid1.datasource=ds. tables["Table1"];
This. Datagrid1.databind ();

}

protected void SetBind2 ()
{

SqlConnection conn2=new SqlConnection (system.configuration.configurationsettings.appsettings["Conn"));
SqlDataAdapter Da2=new SqlDataAdapter ("select * from DEP", CONN2);
DataSet ds2=new DataSet ();
Da2. Fill (DS2, "Table1");



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.