Akhter HUssain

Akhter HUssain

  • 1.2k
  • 692
  • 12.1k

System.Data.DataRowView does not contain a property ?

Sep 27 2019 7:40 AM
when i am pass data from datalist to gridview then this exception is raising that is ,
 
  1. System.Data.DataRowView does not contain a property with the name QTY.  
here is my html 
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CartviewDG.aspx.cs" Inherits="WebApplication1.CartviewDG" %>  
  2.   
  3. <!DOCTYPE html>  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6.      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
  7. <script type="text/javascript">  
  8.     $(function () {  
  9.       
  10.   
  11.         //Calculate and update Grand Total.  
  12.         var grandTotal = 0;  
  13.         $("[id*=lblProductTotal]").each(function () {  
  14.             grandTotalgrandTotal = grandTotal + parseFloat($(this).html());  
  15.         });  
  16.         $("[id*=txtTotal]").val(grandTotal.toString());  
  17.     });  
  18.   
  19.   
  20.   
  21.   
  22.         $(document).ready(function () {  
  23.             $('#txtcustomer').keyboard({  
  24.                 autoAccept: true  
  25.             })  
  26.             .addTyping();  
  27.             $('#txtqty').keyboard({  
  28.                 layout: 'num',  
  29.                 restrictInput: true,  
  30.                 preventPaste: true,  
  31.                 autoAccept: true  
  32.             })  
  33.             .addTyping();  
  34.              
  35.             $('#QTY').keyboard({  
  36.                 layout: 'num',  
  37.                 restrictInput: true,  
  38.                 preventPaste: true,  
  39.                 autoAccept: true  
  40.             })  
  41.             .addTyping();  
  42.         });  
  43. </script>  
  44. <head runat="server">  
  45.     <title></title>  
  46. </head>  
  47. <body>  
  48.     <form id="form1" runat="server">  
  49.         <div>  
  50.             <div>  
  51.     <table class="auto-style1">  
  52.         <tr>  
  53.             <td>  
  54.                 <div>  
  55.                     <asp:DataList ID="dlemp" runat="server" RepeatDirection="Horizontal" RepeatColumns="2">  
  56.                         <ItemTemplate>  
  57.                             <div id="pricePlans">  
  58.                                 <ul id="plans">  
  59.                                     <li class="plan">  
  60.                                         <ul class="planContainer">  
  61.                                             <li class="title">  
  62.                                                 <h2>  
  63.                                                     <asp:Label ID="ProductName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>  
  64.                                                     <br />  
  65.                                             </li>  
  66.                                             <li class="title">  
  67.                                                 <asp:Image ID="imgEmp" Height="100px" Width="100px" runat="server" ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>' />  
  68.                                             </li>  
  69.                                             <li>  
  70.                                                 <ul class="options">  
  71.                                                     <div>  
  72.                                                         <li><b>Id: </b>  
  73.                                                             <asp:Label ID="CustomerID" runat="server" Text=' <%# Eval("Id") %>'></asp:Label>  
  74.                                                             <asp:CheckBox ID="CheckBox1" runat="server" Text="select" OnCheckedChanged="Redirect" />  
  75.                                                             <asp:Button ID="btnadd" runat="server" Text="Add Cart" OnClick="AddToCart"></asp:Button>  
  76.                                                         </li>  
  77.                                                     </div>  
  78.                                                 </ul>  
  79.                                             </li>  
  80.                                         </ul>  
  81.                                     </li>  
  82.                                 </ul>  
  83.                             </div>  
  84.                             </div>  
  85.                         </ItemTemplate>  
  86.                         <FooterTemplate>  
  87.                         </FooterTemplate>  
  88.                     </asp:DataList>  
  89.                 </div>  
  90.                    
  91.             </td>  
  92.             <td>  
  93.                 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">  
  94.                     <Columns>  
  95.                         <asp:TemplateField HeaderText="Image">  
  96.                             <ItemTemplate>  
  97.                                 <asp:Image ID="Data" runat="server" Width="100px" Height="80px" ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>' />  
  98.                             </ItemTemplate>  
  99.                         </asp:TemplateField>  
  100.                         <asp:TemplateField HeaderText="Name">  
  101.                             <ItemTemplate>  
  102.                                 <asp:Label Text='<%#Eval("Name") %>' runat="server" ID="lblName" />  
  103.                             </ItemTemplate>  
  104.                         </asp:TemplateField>  
  105.                         <asp:TemplateField HeaderText="QTY">  
  106.                             <ItemTemplate>  
  107.                                 <asp:TextBox ID="txtqty" onkeyup="CalculateTotals();" Text='<%#Eval("txtqty") %>'  runat="server" Height="16px" Width="33px"></asp:TextBox>  
  108.                             </ItemTemplate>  
  109.                         </asp:TemplateField>  
  110.                            <asp:TemplateField HeaderText="Price">  
  111.                             <ItemTemplate>  
  112.                                 <asp:Label Text='<%#Eval("Price") %>' runat="server" ID="lblPrice" />  
  113.                             </ItemTemplate>  
  114.                         </asp:TemplateField>  
  115.                         <asp:TemplateField HeaderText="Total">  
  116.     <ItemTemplate>  
  117.        <asp:Label ID="lblProductTotal" runat="server"      
  118.         Text='<%# ((Convert.ToInt32(Eval("txtqty")))*(Convert.ToInt32(Eval("Price"))))%>'>  
  119.         </asp:Label>  
  120.     </ItemTemplate>  
  121.                                      </asp:TemplateField>  
  122.                     </Columns>  
  123.                 </asp:GridView>  
  124.             </td>  
  125.         </tr>  
  126.         <tr>  
  127.             <td>  
  128.                    
  129.             </td>  
  130.             <td>  
  131.                    
  132.             </td>  
  133.         </tr>  
  134.     </table>  
  135. </div>  
  136.         </div>  
  137.     </form>  
  138. </body>  
  139. </html>  
  140.          
C# code 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data.SqlClient;  
  8. using System.Configuration;  
  9. using System.Data;  
  10.   
  11. namespace WebApplication1  
  12. {  
  13.     public partial class CartviewDG : System.Web.UI.Page  
  14.     {  
  15.         protected void Page_Load(object sender, EventArgs e)  
  16.         {  
  17.             if (!this.IsPostBack)  
  18.             {  
  19.                 string query = "Select* from Displaymaster";  
  20.                 DataTable dt = GetData(query);  
  21.                 dlemp.DataSource = dt;  
  22.                 dlemp.DataBind();  
  23.             }  
  24.         }  
  25.   
  26.         private static DataTable GetData(string query)  
  27.         {  
  28.             string constr = ConfigurationManager.ConnectionStrings["SPS"].ConnectionString;  
  29.             SqlConnection con = new SqlConnection(constr);  
  30.             SqlCommand cmd = new SqlCommand(query, con);  
  31.             SqlDataAdapter da = new SqlDataAdapter(cmd);  
  32.             DataTable dt = new DataTable();  
  33.             da.Fill(dt);  
  34.             return dt;  
  35.         }  
  36.   
  37.         protected void Redirect(object source, EventArgs e)  
  38.         {  
  39.             string id = "";  
  40.             foreach (DataListItem item in dlemp.Items)  
  41.             {  
  42.                 CheckBox chk = item.FindControl("CheckBox1"as CheckBox;  
  43.                 if (chk.Checked)  
  44.                 {  
  45.                     id += (item.FindControl("CustomerID"as Label).Text + ",";  
  46.                 }  
  47.             }  
  48.             string query = "SELECT * FROM Displaymaster where Id IN(" + id.TrimEnd(',') + ")";  
  49.             DataTable dt = GetData(query);  
  50.             Session["dt"] = dt;  
  51.         }  
  52.   
  53.         protected void AddToCart(object sender, EventArgs e)  
  54.         {  
  55.             DataTable dt = Session["dt"as DataTable;  
  56.             GridView1.DataSource = dt;  
  57.             GridView1.DataBind();  
  58.         }  
  59.   
  60.         protected void Save(object sender, EventArgs e)  
  61.         {  
  62.             DataTable dt = Session["dt"as DataTable;  
  63.             string consString = ConfigurationManager.ConnectionStrings["SPS"].ConnectionString;  
  64.             using (SqlConnection con = new SqlConnection(consString))  
  65.             {  
  66.                 using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))  
  67.                 {  
  68.                     sqlBulkCopy.DestinationTableName = "dbo.tblfilesData";  
  69.                     sqlBulkCopy.ColumnMappings.Add("Name""Name");  
  70.                     sqlBulkCopy.ColumnMappings.Add("Data""Data");  
  71.                     con.Open();  
  72.                     sqlBulkCopy.WriteToServer(dt);  
  73.                     con.Close();  
  74.                 }  
  75.             }  
  76.         }  
  77.         } }  
 

Answers (1)