停止在添加新行时刷新Repeater的数据

时间:2015-01-01 07:32:03

标签: asp.net c#-4.0

下面是我在datatable中插入行的代码,然后我将datatable绑定到repeater:

DataTable dt = new DataTable();
                if (ViewState["cnt"] != null)
                {
                    ViewState["cnt"] = Convert.ToInt32(ViewState["cnt"]) + 1;
                    //DataTable dt = new DataTable();
                    dt.Columns.Add("SrNo", typeof(int));
                    dt.Columns.Add("VisaType", typeof(string));
                    dt.Columns.Add("Nationality", typeof(string));
                    dt.Columns.Add("Name", typeof(string));
                    dt.Columns.Add("DOB", typeof(DateTime));
                    dt.Columns.Add("Gender", typeof(string));
                    dt.Columns.Add("PassportNo", typeof(string));
                    dt.Columns.Add("PassportExpDate", typeof(DateTime));
                    dt.Columns.Add("PP1", typeof(string));
                    dt.Columns.Add("PP2", typeof(string));
                    dt.Columns.Add("Photo", typeof(string));
                    dt.Columns.Add("Rate", typeof(string));
                    dt.Columns.Add("NoOfApplicant", typeof(string));
                    dt.Columns.Add("TotalAmnt", typeof(string));
                    dt.Columns.Add("Table", typeof(int));
                    int SrNO = 1;
                    for (int j = 1; j <= Convert.ToInt32(drpNoOfApplicant.SelectedValue); j++)
                    {
                        dt.Rows.Add(j, drpVisaDuration.SelectedItem.Text, RadCountry.Text, null, null, "Male", null, null, null, null, null, txtVisaAmount.Text, drpNoOfApplicant.SelectedValue, txtTotalAmount.Text, Convert.ToInt32(ViewState["cnt"]));
                        SrNO += SrNO;
                    }
                    DataTable dt1 = (DataTable)ViewState["dt"];
                    dt.Merge(dt1);
                    RptApplicant.DataSource = dt;
                    RptApplicant.DataBind();

                    ViewState["dt"] = dt;
                    //Session["dt"] = dt;
                    //txtVisaType.Text = drpVisaDuration.SelectedItem.Text;
                    //txtNationality.Text = txtNationalityCustomer.Text;
                    txtNoOfApplicant.Text = "";
                }
                else
                {
                    ViewState["cnt"] = 0;

                    dt.Columns.Add("SrNo", typeof(int));
                    dt.Columns.Add("VisaType", typeof(string));
                    dt.Columns.Add("Nationality", typeof(string));
                    dt.Columns.Add("Name", typeof(string));
                    dt.Columns.Add("DOB", typeof(DateTime));
                    dt.Columns.Add("Gender", typeof(string));
                    dt.Columns.Add("PassportNo", typeof(string));
                    dt.Columns.Add("PassportExpDate", typeof(DateTime));
                    dt.Columns.Add("PP1", typeof(string));
                    dt.Columns.Add("PP2", typeof(string));
                    dt.Columns.Add("Photo", typeof(string));
                    dt.Columns.Add("Rate", typeof(string));
                    dt.Columns.Add("NoOfApplicant", typeof(string));
                    dt.Columns.Add("TotalAmnt", typeof(string));
                    dt.Columns.Add("Table", typeof(int));
                    int SrNO = 1;
                    for (int j = 1; j <= Convert.ToInt32(drpNoOfApplicant.SelectedValue); j++)
                    {
                        dt.Rows.Add(j, drpVisaDuration.SelectedItem.Text, RadCountry.Text, null, null, "Male", null, null, null, null, null, txtVisaAmount.Text, drpNoOfApplicant.SelectedValue, txtTotalAmount.Text, Convert.ToInt32(ViewState["cnt"]));
                        SrNO += SrNO;
                    }
                    RptApplicant.DataSource = dt;
                    RptApplicant.DataBind();

                    ViewState["dt"] = dt;
                    //Session["dt"] = dt;
                    //txtVisaType.Text = drpVisaDuration.SelectedItem.Text;
                    //txtNationality.Text = txtNationalityCustomer.Text;
                    txtNoOfApplicant.Text = "";
                }

现在当我添加新行时,填充的数据会刷新,这里我想停止刷新该数据。我被困在这段代码中,请回复我。enter image description here

0 个答案:

没有答案