DataBinding:' System.Data.DataRowView'不包含名称为' Disp_id'的属性

时间:2017-04-11 11:56:46

标签: asp.net

public partial class dispmgmt : System.Web.UI.Page
{
    String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection();
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void Button2_Click1(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvbind();
        }

            GridView1.Visible = true;
            this.BindData();


        String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = " Select DISTINCT CallType, Format, Disposition, SUbDisposition  from CallCenter..Loy_DispMstr where CallType=@CallType and Format=@Format and Disposition = @Disposition and  SubDisposition =@Disposition";
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();
        cmd.Parameters.AddWithValue("@CallType", ddlCalltype.SelectedValue);
        cmd.Parameters.AddWithValue("@Format", ddlFormat.SelectedValue);
        cmd.Parameters.AddWithValue("@Disposition ", ddlDisp.SelectedValue);
        cmd.Parameters.AddWithValue("@SubDisposition", ddlSubdisp.SelectedValue);
        cmd.Connection = con;
        cmd.ExecuteNonQuery();
        da.SelectCommand = cmd;
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();


    }





    protected void ddlCalltype_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlCalltype.SelectedIndex != 0)
        { 

            String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter sda = new SqlDataAdapter();
            DataSet dsFormat = new DataSet();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select Formatid,Formatdetail,dispformat  From loy_Formatdetail with (nolock) Where isactive='1' and memberstatus = 'Member' order by FormatDetail";
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            sda.Fill(dsFormat);

                ddlFormat.DataValueField = "DISPFORMAT";
                ddlFormat.DataTextField = "FORMATDETAIL";
                ddlFormat.DataSource = dsFormat.Tables[0];
                ddlFormat.DataBind();
                ddlFormat.Items.Insert(0, "<----Select---->");



        }
        else
        {
            ddlFormat.Items.Clear();

        }

    }
    protected void ddlFormat_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlFormat.SelectedIndex != 0)
        {

            String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;

            SqlConnection con1 = new SqlConnection(strConnString);


            con1.Open();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter sda = new SqlDataAdapter();
            DataSet dsDisp = new DataSet();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select DISTINCT Disposition from CallCenter..Loy_DispMstr where CallType=@CallType and SUBFormat=@Format";
            cmd.Parameters.AddWithValue("@CallType", ddlCalltype.SelectedValue);
            cmd.Parameters.AddWithValue("@Format", ddlFormat.SelectedItem.Text);
            cmd.Connection = con1;
            cmd.ExecuteNonQuery();

            sda.SelectCommand = cmd;
            sda.Fill(dsDisp);


            ddlDisp.DataTextField = "Disposition";
            ddlDisp.DataValueField = "Disposition";

            ddlDisp.DataSource = dsDisp.Tables[0];
            ddlDisp.DataBind();

            ddlDisp.Items.Insert(0, "<----Select---->");
            ddlDisp.Focus();
        }
    }




    protected void ddlDisp_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlDisp.SelectedIndex != 0)
        {
            String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd=new SqlCommand();
            SqlDataAdapter sda = new SqlDataAdapter();
            DataSet dsSubDisp = new DataSet();

            using (cmd = new SqlCommand("Select distinct CallType,Disposition,SubDisposition,Format from  Loy_DispMstr where CallType=@CallType and SUBFormat=@Format and Disposition = @disposition", con))
            {
                cmd.Parameters.AddWithValue("@CallType",ddlCalltype.SelectedValue);
                cmd.Parameters.AddWithValue("@Format", ddlFormat.SelectedValue);
                cmd.Parameters.AddWithValue("@disposition", ddlDisp.SelectedValue);
                con.Open();
                cmd.ExecuteNonQuery();

            }
            sda.SelectCommand = cmd;
            sda.Fill(dsSubDisp);
               {

                    ddlSubdisp.DataTextField = "SubDisposition";
                    ddlSubdisp.DataValueField = "SubDisposition";
                    ddlSubdisp.DataSource = dsSubDisp.Tables[0];
                    ddlSubdisp.DataBind();

                    ddlSubdisp.Items.Insert(0, "<----Select---->");
                    ddlSubdisp.SelectedIndex = 0;
                    ddlSubdisp.Focus();

               //     ddlDisp.Items.Insert(1, "ADD NEW VALUE");
                //    ddlDisp.SelectedIndex = 1;
                //    ddlDisp.Focus();



                }
            }
         /*   if (ddlDisp.SelectedItem.Text == "ADD NEW VALUE" )
                   {
                        TextBox1.Visible = true;
                        TextBox2.Visible = true;
                   }*/
        }


    protected void ddlSubdisp_SelectedIndexChanged(object sender, EventArgs e)
    {
        String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;

        SqlConnection con = new SqlConnection(strConnString);

        SqlDataAdapter sda = new SqlDataAdapter();
        DataSet dsOut = new DataSet();

        SqlCommand cmd = new SqlCommand("select PID,Memberstatus,calltype,format,disposition,subdisposition, man_data,creation_date,createdby,updation_date,updatedby from Loy_SubPlaceholder");
            cmd.Connection = con; 
            sda.SelectCommand = cmd;
            sda.Fill(dsOut);
            ddlDisp.DataSource = dsOut.Tables[0];
            ddlDisp.DataValueField = "subdisposition";
            ddlDisp.DataTextField = "subdisposition";
            ddlDisp.DataBind();
            con.Open();

            cmd.ExecuteNonQuery();



    }
   private void BindData()
    {
        String strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        con.Open();


        string query = " Select DISTINCT Disp_id ,CallType, Format, Disposition, SUbDisposition  from CallCenter..Loy_DispMstr where CallType=@CallType and Format=@Format and Disposition = @Disposition and  SubDisposition =@Disposition";
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable();
        SqlCommand cmd = new SqlCommand(query);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@CallType", ddlCalltype.SelectedValue);
        cmd.Parameters.AddWithValue("@Format", ddlFormat.SelectedValue);
        cmd.Parameters.AddWithValue("@Disposition ", ddlDisp.SelectedValue);
        cmd.Parameters.AddWithValue("@SubDisposition", ddlSubdisp.SelectedValue);
        cmd.Connection = con;
        cmd.ExecuteNonQuery();
        da.SelectCommand = cmd;
        da.Fill(dt);
        GridView1.DataSource = dt;

        GridView1.DataSource = GetData(cmd);
        GridView1.DataBind();
    }

    private DataTable GetData(SqlCommand cmd)
    {
        string strConnString = ConfigurationManager.ConnectionStrings["CallcenterConnectionString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(strConnString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(dt);
                    Session["dstablegvassign"] = dt;
                    return dt;
                }
            }
        }
    }
    protected void gvbind()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from  dbo.Loy_DispMstr", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            GridView1.DataSource = ds;
            GridView1.DataBind();
            int columncount = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "No Records Found";
        }

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lbldeleteid = (Label)row.FindControl("lblID");
        con.Open();
        SqlCommand cmd = new SqlCommand("delete FROM dbo.Loy_DispMstr where Disp_id='" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString()) + "'", con);
        cmd.ExecuteNonQuery();
        con.Close();
        gvbind();

    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        gvbind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int Disp_id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lblID = (Label)row.FindControl("lblID");
        //TextBox txtname=(TextBox)gr.cell[].control[];
        TextBox textCallType = (TextBox)row.Cells[0].Controls[0];
        TextBox textFormat = (TextBox)row.Cells[1].Controls[0];
        TextBox textDisposition = (TextBox)row.Cells[2].Controls[0];
        TextBox textSUBDisposition = (TextBox)row.Cells[3].Controls[0];
        //TextBox textadd = (TextBox)row.FindControl("txtadd");
        //TextBox textc = (TextBox)row.FindControl("txtc");
        GridView1.EditIndex = -1;
        con.Open();
        //SqlCommand cmd = new SqlCommand("SELECT * FROM detail", conn);
        SqlCommand cmd = new SqlCommand("update detail set CallType='" + textCallType.Text + "',Format='" + textFormat.Text + "',Disposition='" + textDisposition.Text + "',SUBDisposition='" + textSUBDisposition.Text + "'where id='" + Disp_id + "'", con);
        cmd.ExecuteNonQuery();
        con.Close();
        gvbind();
        //GridView1.DataBind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        gvbind();
    }

   protected void Button4_Click(object sender, EventArgs e)
   {
       string disp = TextBox1.Text.Trim();
       if (!string.IsNullOrEmpty(disp))
       {
           ddlDisp.Items.Add(new ListItem(disp, disp));
       }
   }

1 个答案:

答案 0 :(得分:0)

您可能在GridView中的某处使用Disp_id,例如<%# Eval("Disp_id") %>DataKeyNames="Disp_id"。这意味着Disp_id必须存在于绑定到GridView的每个数据库结果集中。 并且Button2_Click1

中的查询至少缺少它