我用formview控件做一个提交的页面,默认显示的insert。
现在遇到3个问题大家看是否能帮忙下
1我编辑模板中的insert。需要把第一个textbox值让他自动获取当前日期时间
2对这些内置的控件如何编写代码,比如在formview中放一个按钮1个日历控件。需要点按钮才让日历控件下显示,如果不用formview直接就可以通过做按钮事件了,但是将按钮放在控件里面则无法
3日历控件我如何设置让他的默认日期是当前日期谢谢

解决方案 »

  1.   

    <%@ Page Language="C#" MasterPageFile="~/App_Admin/WebDateOut.master" AutoEventWireup="true" CodeFile="TEST4.aspx.cs" Inherits="App_Admin_TEST4" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <p>
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" 
                ShowFooter="True" PageSize="3">
                <Columns>
                    <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                        ReadOnly="True" SortExpression="id" />
                    <asp:BoundField DataField="mingcheng" HeaderText="mingcheng" 
                        SortExpression="mingcheng" />
                    <asp:BoundField DataField="address" HeaderText="address" 
                        SortExpression="address" />
                    <asp:BoundField DataField="selecta" HeaderText="selecta" 
                        SortExpression="selecta" />
                    <asp:TemplateField>
                        <FooterTemplate>
                            <asp:CheckBox ID="CheckBox2" runat="server" onclick="CheckAll(this)" title="全选/全不选" />
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:MuserConnectionString2 %>" 
                SelectCommand="SELECT * FROM [test]"></asp:SqlDataSource>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        </p>
        <p>
        </p>
        <p>
        </p>
          <script language="javascript" type="text/javascript">
              //实现GridView的CheckBox全部选择和全部取消
              function CheckAll(checkbox) {
                  var elements = checkbox.form.elements;
                  for (var i = 0; i < elements.length; i++) {
                      if (elements[i].type == "checkbox" && elements[i].id != checkbox.id) {
                          elements[i].checked = checkbox.checked;
                      }
                  }
              }
    </script>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
    </asp:Content>
    代码:
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class App_Admin_TEST4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in this.GridView1.Rows)
            {
                CheckBox CheckRow = (CheckBox)row.FindControl("CheckBox1");
                if (CheckRow.Checked)
                {
                    
                    string id = this.GridView1.DataKeys[row.RowIndex].Values["id"].ToString();
                    Response.Write(id.ToString());
                }
            }
        }
    }
      

  2.   

    protected void Button1_Click(object sender, EventArgs e) 
        { 
            List<string> listID=new List<string>
            foreach (GridViewRow row in this.GridView1.Rows) 
            { 
                CheckBox CheckRow = (CheckBox)row.FindControl("CheckBox1"); 
                if (CheckRow.Checked) 
                { 
                    
                    //string id = this.GridView1.DataKeys[row.RowIndex].Values
    //["id"].ToString(); 
                    listID.Add(this.GridView1.DataKeys[row.RowIndex].Values["id"].ToString());
                    //Response.Write(id.ToString()); 
                } 
            } 
        } 
      

  3.   

    protected void Button1_Click(object sender, EventArgs e)
        {            List<string> listID=new List<string>
            foreach (GridViewRow row in this.GridView1.Rows) 
            { 
                CheckBox CheckRow = (CheckBox)row.FindControl("CheckBox1"); 
                if (CheckRow.Checked) 
                { 
                    
                    //string id = this.GridView1.DataKeys[row.RowIndex].Values
                    //["id"].ToString(); 
                    listID.Add(this.GridView1.DataKeys[row.RowIndex].Values["id"].ToString());
                    //Response.Write(id.ToString()); 
                } 
            } 
        }
      

  4.   

    例如你的TextBox的id为selecta,Calendar的id为Calendar1
    则在1,3问题在FormView1的DataBound事件中解决,
        protected void FormView1_DataBound(object sender, EventArgs e)
        {
            ((TextBox)FormView1.FindControl("selecta")).Text = DateTime.Today.ToString();
            ((Calendar)FormView1.FindControl("Calendar1")).SelectedDate = DateTime.Today;
        }2的问题在Calendar的SelectionChanged事件中解决,
        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            ((TextBox)FormView1.FindControl("selecta")).Text = ((Calendar)FormView1.FindControl("Calendar1")).SelectedDate.ToString();
        }
      

  5.   

    谢谢了这个我找到答案了,是在询问另外个问题,以前没人回复我就没法结贴,然后把新的问题贴在这边找个网友帮忙看看的是http://topic.csdn.net/u/20091126/11/90bf3be7-772a-4b21-993c-184c2a30d5a2.html的问题