我用formview控件做一个提交的页面,默认显示的insert。
现在遇到3个问题大家看是否能帮忙下
1我编辑模板中的insert。需要把第一个textbox值让他自动获取当前日期时间
2对这些内置的控件如何编写代码,比如在formview中放一个按钮1个日历控件。需要点按钮才让日历控件下显示,如果不用formview直接就可以通过做按钮事件了,但是将按钮放在控件里面则无法
3日历控件我如何设置让他的默认日期是当前日期谢谢
现在遇到3个问题大家看是否能帮忙下
1我编辑模板中的insert。需要把第一个textbox值让他自动获取当前日期时间
2对这些内置的控件如何编写代码,比如在formview中放一个按钮1个日历控件。需要点按钮才让日历控件下显示,如果不用formview直接就可以通过做按钮事件了,但是将按钮放在控件里面则无法
3日历控件我如何设置让他的默认日期是当前日期谢谢
解决方案 »
- The hostname could not be parsed(域名不能解析)
- HttpModules 和 HttpHandlers能否捕捉ASP页面?
- 急 mvc3分页问题
- GIRDVIEW绑定问题求救
- |M| 有没有什么办法记我生成的DLL 不被Reflector.exe这个工具看到我的源码
- 表中有几个字段,各字段内部内容之间用逗号分割,要实现如下几个操作,求一存储过程
- 装上.net 后我原来的ASP网页怎么都打不开了?aspx的都可以
- 为何不能捕捉System.Security.SecurityException异常??
- ASP.NET:如何获取用户点击浏览器刷新按钮的事件?
- 超級急!!請幫助,我的.net studio出現了這樣的問題
- 省市县数据库 带邮编 区号
- 谁有上传控件?
</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());
}
}
}
}
{
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());
}
}
}
{ 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());
}
}
}
则在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();
}