when i am pass data from datalist to gridview then this exception is raising that is ,
- System.Data.DataRowView does not contain a property with the name QTY.
here is my html
C# code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Data;
-
- namespace WebApplication1
- {
- public partial class CartviewDG : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- string query = "Select* from Displaymaster";
- DataTable dt = GetData(query);
- dlemp.DataSource = dt;
- dlemp.DataBind();
- }
- }
-
- private static DataTable GetData(string query)
- {
- string constr = ConfigurationManager.ConnectionStrings["SPS"].ConnectionString;
- SqlConnection con = new SqlConnection(constr);
- SqlCommand cmd = new SqlCommand(query, con);
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- da.Fill(dt);
- return dt;
- }
-
- protected void Redirect(object source, EventArgs e)
- {
- string id = "";
- foreach (DataListItem item in dlemp.Items)
- {
- CheckBox chk = item.FindControl("CheckBox1") as CheckBox;
- if (chk.Checked)
- {
- id += (item.FindControl("CustomerID") as Label).Text + ",";
- }
- }
- string query = "SELECT * FROM Displaymaster where Id IN(" + id.TrimEnd(',') + ")";
- DataTable dt = GetData(query);
- Session["dt"] = dt;
- }
-
- protected void AddToCart(object sender, EventArgs e)
- {
- DataTable dt = Session["dt"] as DataTable;
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
-
- protected void Save(object sender, EventArgs e)
- {
- DataTable dt = Session["dt"] as DataTable;
- string consString = ConfigurationManager.ConnectionStrings["SPS"].ConnectionString;
- using (SqlConnection con = new SqlConnection(consString))
- {
- using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
- {
- sqlBulkCopy.DestinationTableName = "dbo.tblfilesData";
- sqlBulkCopy.ColumnMappings.Add("Name", "Name");
- sqlBulkCopy.ColumnMappings.Add("Data", "Data");
- con.Open();
- sqlBulkCopy.WriteToServer(dt);
- con.Close();
- }
- }
- }
- } }