日期:2014-05-18 浏览次数:20458 次
<body> <form id="form1" runat="server"> <div> </div> <cc1:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server"> </cc1:ScriptManager> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <cc1:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> <asp:GridView ID="GridView1" runat="server" Height="205px" Width="554px" AutoGenerateColumns="False" DataKeyNames="id" OnRowEditing="GridView1_RowEditing" > <Columns> <asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" /> <asp:BoundField DataField="passWord" HeaderText="passWord" SortExpression="passWord" /> <asp:BoundField DataField="userClass" HeaderText="userClass" SortExpression="userClass" /> <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SalesDBConnectionString %>" SelectCommand="SELECT [userName], [passWord], [userClass], [id] FROM [admin]"></asp:SqlDataSource> <cc2:TimerControl ID="TimerControl1" runat="server"> </cc2:TimerControl> <%-- <cc2:TimerControl ID="TimerControl1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </cc2:TimerControl>--%> </ContentTemplate> </cc1:UpdatePanel> </form> <script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <references> </references> <components> </components> </page> </script> </body>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { showdb(); } } private void showdb() { SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]); SqlDataAdapter da = new SqlDataAdapter("select * from admin", con); DataSet ds = new DataSet(); da.Fill(ds,"users"); this.GridView1.DataSource = ds.Tables["users"]; this.GridView1.DataBind(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { this.GridView1.EditIndex = e.NewEditIndex; showdb(); }