• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ASP.NETRepeater绑定DropDownListCalendar选择日期

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;using System.Text;
using System.IO;
using System.Data;


public partial class DownloadItem_CmdExeItem : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            Btn_Commit_BCF.Attributes.Add("OnClick", "javascript:return confirm('您确定提交吗?!');");
            
        }
        
    }
protected void Btn_search_BCF_Click(object sender, EventArgs e)
    {
        InitData();
        rpt_BCF_DataBinds();
        TotalControls = Rpt_BCF.Items.Count;
        for (int i = 0; i < TotalControls; i++)
        {
            (Rpt_BCF.Items[i].FindControl("DropDownList1") as DropDownList).Enabled = false;

        }
    }
protected void Rpt_BCF_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            (e.Item.FindControl("DropDownList1") as DropDownList).SelectedValue = DDL_Seach_City.SelectedItem.Value;
        }
    }
    protected void Btn_addline_BCF_Click(object sender, EventArgs e)
    {
        DataTable dt = CopyFormData();
        Random rd_year = new Random(), rd_month = new Random(), rd_date = new Random();
        string datestr = rd_year.Next(1, 9999).ToString("d4") + "/" + rd_month.Next(1, 12).ToString("d2") + "/" + rd_date.Next(1, 30).ToString("d2");
        DataRow dr = dt.NewRow();


        dr["HIDUKE"] = datestr;//DateTime.Now.Date.ToString();
        dr["PV_CNT"] = -1;
        dr["CL_CNT"] = -1;
        dt.Rows.Add(dr);

        ViewState.Add("Data", dt);

        rpt_BCF_DataBinds();
        for (int i = 0; i < TotalControls; i++)
        {
            (Rpt_BCF.Items[i].FindControl("DropDownList1") as DropDownList).Enabled = false;
            (Rpt_BCF.Items[i].FindControl("TextBox2") as TextBox).Enabled = false;
            (Rpt_BCF.Items[i].FindControl("Btn_repcld") as Button).Enabled = false;

        }


        Btn_search_BCF.Enabled = false;

    }
    private void Phl_table_addline(int num)
    {
        //for (int i = 0; i < num; i++)
        //{ 
        TableRow tr;
        TableCell tc;
        DropDownList ddl_citydynamic;
        ListItem li;
        Calendar cld;
        TextBox Tbox_date, Tbox_pvno, Tbox_clno;
        Button Btn_chosedate;
        //if(IsPostBack)
        //{

        tr = new TableRow();

        tc = new TableCell();
        ddl_citydynamic = new DropDownList();
        li = new ListItem("请xx", "-1");
        ddl_citydynamic.Items.Add(li);
        li = new ListItem("xxx", "1");
        ddl_citydynamic.Items.Add(li);
        li = new ListItem("xxx", "2");
        ddl_citydynamic.Items.Add(li);
        li = new ListItem("xxx", "3");
        ddl_citydynamic.Items.Add(li);
        li = new ListItem("xxx", "4");
        ddl_citydynamic.Items.Add(li);
        li = new ListItem("xxx", "5");
        ddl_citydynamic.Items.Add(li);
        tc.Controls.Add(ddl_citydynamic);
        tr.Cells.Add(tc);

        tc = new TableCell();
        Tbox_date = new TextBox();
        Btn_chosedate = new Button();
        Btn_chosedate.Text = "";
        tc.Controls.Add(Tbox_date);
        tc.Controls.Add(Btn_chosedate);
        tr.Cells.Add(tc);

        tc = new TableCell();
        Tbox_pvno = new TextBox();
        tc.Controls.Add(Tbox_pvno);
        tr.Cells.Add(tc);

        tc = new TableCell();
        Tbox_clno = new TextBox();
        tc.Controls.Add(Tbox_clno);
        tr.Cells.Add(tc);

        tc = new TableCell();
        tr.Cells.Add(tc);

        //tbl_BCF.Rows.Add(tr);
        //}

    }
    protected int CurrentItem
    {
        get
        {
            return ViewState["CurrentItem"] == null ? 0 : (int)(ViewState["CurrentItem"]);
        }
        set
        {
            ViewState["CurrentItem"] = value;
        }
    }
    protected int TotalControls
    {
        get
        {
            return ViewState["TotControls"] == null ? 0 : (int)(ViewState["TotControls"]);
        }
        set
        {
            ViewState["TotControls"] = value;
        }
    }
  protected void rpt_BCF_DataBinds()
    {
        Rpt_BCF.DataSource = ViewState["Data"] as DataTable;
        Rpt_BCF.DataBind();
    }
    protected DataTable CopyFormData()
    {
        DataTable dt = (ViewState["Data"] as DataTable).Clone();

        foreach (RepeaterItem ri in Rpt_BCF.Items)
        {
            DataRow dr = dt.NewRow();

            dr["xxx"] = (ri.FindControl("TextBox1") as TextBox).Text;
         
            dt.Rows.Add(dr);
        }

        return dt;
    }

    protected void InitData()
    {
        DateTime time = DateTime.Now;

        DataTable dt = new DataTable();

        StringBuilder sb = new StringBuilder();
        sb.Append("select xxx,xxx,xxx,xxx from 00 where ");

        if (DDL_Seach_City.SelectedItem.Text != "请选择")
            sb.Append("xxx='" + DDL_Seach_City.SelectedItem.Text + "' and ");
        if (TBox_Datebegin.Text.Length == 10 && TBox_Dateend.Text.Length == 10)
            sb.Append("xxx>='" + TBox_Datebegin.Text + "' and xxx<='" + TBox_Dateend.Text + "' and ");
        else if (TBox_Datebegin.Text.Length == 10)
            sb.Append("xxx='" + TBox_Datebegin.Text + "' and ");

        if (sb.Length <= 62)
        { }
        else
        {

            string sqlstr = sb.ToString().Substring(0, sb.Length - 5);
            BCF bcfr = new BCF();
            dt = bcfr.search_BCF(sqlstr);
        }

        ViewState.Add("Data", dt);
    }
    protected void Btn_repcld_Click(object sender, EventArgs e)
    {
        RepeaterItem rptItem = ((Button)sender).Parent as RepeaterItem;
        CurrentItem = rptItem.ItemIndex;
        Div_Cld_common.Style["Display"] = "Block";
    }
 protected void Cld_common_SelectionChanged(object sender, EventArgs e)
    {
        (Rpt_BCF.Items[CurrentItem].FindControl("TextBox2") as TextBox).Text = Cld_common.SelectedDate.ToShortDateString();
        Div_Cld_common.Style["Display"] = "None";
    }
}

前台:

<div class="new_area_BCF">
                    <table style="width: 900px; text-align: center; align-self: center;">
                        <tr>
                            <td class="auto-style1">
                                <asp:Label ID="Label1" runat="server" Text="城市"></asp:Label><asp:DropDownList ID="DDL_Seach_City" runat="server">
                                    <asp:ListItem Text="请选择" Value="-1"></asp:ListItem>
                                    <asp:ListItem Text="xx" Value="1"></asp:ListItem>
                                    <asp:ListItem Text="xx" Value="2"></asp:ListItem>
                                    <asp:ListItem Text="xx" Value="3"></asp:ListItem>
                                    <asp:ListItem Text="xx" Value="4"></asp:ListItem>
                                    <asp:ListItem Text="xx" Value="5"></asp:ListItem>
                                </asp:DropDownList></td>

                            <td style="text-align: right;" class="auto-style1">
                                <asp:Label ID="Label2" runat="server" Text="日期"></asp:Label>
                                <asp:TextBox ID="TBox_Datebegin" runat="server"></asp:TextBox>
                                <asp:Button ID="Btn_Datebegin" runat="server" Text="▼" OnClick="Btn_Datebegin_Click" />~
                            </td>
                            <td style="text-align: left;" class="auto-style1">
                                <asp:TextBox ID="TBox_Dateend" runat="server"></asp:TextBox>
                                <asp:Button ID="Btn_Dateend" runat="server" Text="▼" OnClick="Btn_Dateend_Click" />
                            </td>
                            <td class="auto-style1">
                                <asp:Button ID="Btn_search_BCF" runat="server" Text="检索" OnClick="Btn_search_BCF_Click" /><asp:Button ID="Btn_addline_BCF" OnClick="Btn_addline_BCF_Click" runat="server" Text="+" />
                            </td>
                            <td class="auto-style1"></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td style="text-align: right;">
                                <asp:Calendar ID="Cld_begin" Visible="false" runat="server" OnSelectionChanged="Cld_begin_SelectionChanged"></asp:Calendar>
                            </td>
                            <td style="text-align: left;">
                                <asp:Calendar ID="Cld_end" Visible="false" runat="server" OnSelectionChanged="Cld_end_SelectionChanged"></asp:Calendar>
                            </td>
                            <td></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan="5">
                                <asp:Repeater ID="Rpt_BCF" runat="server" OnItemDataBound="Rpt_BCF_ItemDataBound">
                                    <HeaderTemplate>
                                        <table class="Rpt_table_BCF">
                                            <tr>
                                                <th>xx</th>
                                                <th>xx</th>
                                                <th>xx</th>
                                                <th>xx</th>
                                                <th></th>
                                            </tr>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr class="tr_white_BCF">
                                            <td>
                                                <asp:DropDownList ID="DropDownList1" runat="server" OnDataBinding="DropDownList1_DataBinding">
                                                    <asp:ListItem Text="请选择" Value="-1"></asp:ListItem>
                                                    <asp:ListItem Text="xxx" Value="1"></asp:ListItem>
                                                    <asp:ListItem Text="xxx" Value="2"></asp:ListItem>
                                                    <asp:ListItem Text="xxx" Value="3"></asp:ListItem>
                                                    <asp:ListItem Text="xxx" Value="4"></asp:ListItem>
                                                    <asp:ListItem Text="xxx" Value="5"></asp:ListItem>
                                                </asp:DropDownList>
                                                <asp:TextBox ID="TextBox1" Text='<%#Eval("xxx")%>' Visible="false" runat="server"></asp:TextBox></td>
                                            <td>
                                                <asp:TextBox ID="TextBox2" Text='<%#Eval("xxx")%>' runat="server"></asp:TextBox><asp:Button ID="Btn_repcld" OnClick="Btn_repcld_Click" runat="server" Text="▼" /></td>
                                            <td>
                                                <asp:TextBox ID="TextBox3" Text='<%#Eval("xxx")%>' runat="server"></asp:TextBox></td>
                                            <td>
                                                <asp:TextBox ID="TextBox4" Text='<%#Eval("xxx")%>' runat="server"></asp:TextBox></td>
                                            <td></td>
                                        </tr>
                                    </ItemTemplate>
                                    <%--<AlternatingItemTemplate>
                                         <tr class="tr_black_BCF">
                                            <td><%#Eval("xxx")%></td>
                                            <td><%#Eval("xxx")%></td>
                                            <td>
                                                <asp:TextBox ID="TextBox1" Text='<%#Eval("xxx")%>' runat="server"></asp:TextBox></td>
                                            <td>
                                                <asp:TextBox ID="TextBox2" Text='<%#Eval("xxx")%>' runat="server"></asp:TextBox></td>
                                            <td>
                                                </td>
                                        </tr>
                                    </AlternatingItemTemplate>--%>
                                    <FooterTemplate>
                                        </table>
                                    </FooterTemplate>
                                </asp:Repeater>
                                <div id="Div_Cld_common" runat="server">
                                    <asp:Calendar ID="Cld_common" runat="server" OnSelectionChanged="Cld_common_SelectionChanged"></asp:Calendar>
                                </div>
                            </td>

                        </tr>
                        <tr>
                            <td colspan="5" style="text-align: right;">
                                <asp:Button ID="Btn_Commit_BCF" runat="server" Text="提交" OnClick="Btn_Commit_BCF_Click" /></td>

                        </tr>
                        <tr><td><p>
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                    <br />
                     
                       
                    
                    

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ASP.NET Core 数据保护(Data Protection)【上】发布时间:2022-07-10
下一篇:
iis站点asp.net网站访问弹出提示框发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap