Kim_zh

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

2013-09-26 10:33:55

1、书写TextBox标签来填写日期,通过强制转换来确保日期的格式:

  txt日期.Text =Convert.ToDateTime(row["日期"]).ToString("yyyy-MM-dd");  

  判断格式是否正确的代码:

      try
                {
                    DateTime dt = Convert.ToDateTime(txt日期.Text.Trim());
                }
                catch
                {
                    OutInfo("发布时间格式错误");
                    return;
                }

  提取当前日期的所有格式:   

  string dt= DateTime.Now.ToString("yyyyMMddHHmmssfffffff");

2、名为“类别”的RadioButton的反绑数据:

  if (row["类别"].ToString() == "2")
            {
                RadioButton1.Checked = true;
            }
            else
            {
                RadioButton2.Checked = true;
            }

3、名为“类别”的CheckBox的查询筛选方法

  protected string 获取类别()
        {
            string 类别 = string.Empty;

    //类别为int型,1,2,3分别代表了三种不同的类型
            if (chk信息.Checked)
            {
                类别 = "1,";
            }
            if (chk附件.Checked)
                类别 += "2,";
            if (chk简报.Checked)
                类别 += "3,";
            if (类别.Length > 0)
                return 类别.Substring(0, 类别.Length - 1);
            return 类别;
        }

  之后就可以在数据绑定方法中

   protected void BindData(string 标题)
        {           
            msgInfo1.DataSource = Public.获取发布列表(标题, 获取类别());
            msgInfo1.DataBind();
        }

  在查询方法中就可以直接调用绑定方法实现查询功能

  protected void btn查询_Click(object sender, EventArgs e)
        {
            msgInfo1.CurrentPageIndex = 0;
            BindData(txt标题.Text.Trim());
        }

4、然而,在DataGrid中的按钮,需要对“类别”进行筛选的话,则可以采用存储过程来实现对“类别”筛选:

  protected void msgInfo1_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "toUpdate")
            {

      //存储过程获取类别信息
                string 类别 = Comm.获取数据("信息发布", "ID", e.CommandArgument.ToString(), "发布时间 desc").Rows[0]["类别"].ToString();
                if (类别 == "1")
                {
                    Response.Write("<script>window.open('ImforEMS.aspx?ID=" + e.CommandArgument.ToString() + "','','width=305px,height=240px')</script>");
                }
                else
                {
                    Response.Write("<script>window.open('DownBriefing.aspx?ID=" + e.CommandArgument.ToString() + "','','width=305px,height=240px')</script>");
                } 
            }
            else if (e.CommandName == "toDelete")
            {
                try
                {
                    Comm.删除数据("信息发布",e.CommandArgument.ToString());
                    OutInfo("删除成功");
                    BindData(txt标题.Text.Trim());
                }
                catch (Exception ex)
                {
                    OutInfo(ex.Message);
                }
            }         
        }

5、当新增、更新数据之后,需要对其页面进行刷新,并弹出提示信息:

  Response.Write("<script>alert('新增成功');window.opener.location.href=window.opener.location.href;window.close();</script>");

posted on 2013-09-26 11:24  Kim.zh  阅读(143)  评论(0编辑  收藏  举报