Sr不会增加数据表合并

时间:2015-01-01 09:13:46

标签: c# asp.net datatables

下面是我在数据表中插入数据的代码现在当我合并数据时,SrNo没有增加,它显示如下数据,我不知道我的代码中的确切问题是什么:

1 Vikash
2 Dharmesh
1 Niraj
2 Rakesh

我想要如下数据:

    1 Vikash
    2 Dharmesh
    3 Niraj
    4 Rakesh

我的完整代码如下:

if (drpNoOfApplicant.SelectedValue.ToString() != "0" && drpVisaOption.SelectedValue.ToString() != "0")
        {
            //divVisaNationality.Enabled = true;
            lbtnConfirm.Visible = false;
            divApplicant.Visible = true;
            //divlist.Visible = false;
            //lblVisaType.Text = drpVisaType.SelectedValue + " " + drpVisaDuration.SelectedValue;
            lblVisaType.Text = drpVisaDuration.SelectedItem.Text;
            //drpVisaDuration.SelectedItem.Text = "";
            DataTable dt2 = (DataTable)ViewState["dt"];
            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 No = Convert.ToInt32(ViewState["SrNo"]);
                int SrNO = No + 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"];
                DataTable dt3 = new DataTable();
                var tbl = dt3;
                tbl.Merge(dt1);
                RptApplicant.DataSource = tbl;
                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;
                }
                ViewState["SrNo"] = SrNO;
                RptApplicant.DataSource = dt;
                RptApplicant.DataBind();

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

        }

0 个答案:

没有答案