formview控件使用问题

redfalson 2009-11-05 10:15:38
我用formview控件做一个提交的页面,默认显示的insert。
现在遇到3个问题大家看是否能帮忙下
1我编辑模板中的insert。需要把第一个textbox值让他自动获取当前日期时间
2对这些内置的控件如何编写代码,比如在formview中放一个按钮1个日历控件。需要点按钮才让日历控件下显示,如果不用formview直接就可以通过做按钮事件了,但是将按钮放在控件里面则无法
3日历控件我如何设置让他的默认日期是当前日期谢谢
...全文
348 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
redfalson 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 redfalson 的回复:]
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());
            }
        }
    }
[/Quote]谢谢了这个我找到答案了,是在询问另外个问题,以前没人回复我就没法结贴,然后把新的问题贴在这边找个网友帮忙看看的是http://topic.csdn.net/u/20091126/11/90bf3be7-772a-4b21-993c-184c2a30d5a2.html的问题
koukoujiayi 2009-11-26
  • 打赏
  • 举报
回复
例如你的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();
}
redfalson 2009-11-26
  • 打赏
  • 举报
回复
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());
}
}
}
stning 2009-11-26
  • 打赏
  • 举报
回复
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());
}
}
}
redfalson 2009-11-26
  • 打赏
  • 举报
回复
<%@ 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());
}
}
}
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧