TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Akhter HUssain
719
1.3k
101.9k
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 ,
System.Data.DataRowView does not contain a property with the name QTY.
here is my html
<
%@ Page
Language
=
"C#"
AutoEventWireup
=
"true"
CodeBehind
=
"CartviewDG.aspx.cs"
Inherits
=
"WebApplication1.CartviewDG"
%
>
<!DOCTYPE html
>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
script
type
=
"text/javascript"
src
=
"https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
>
</
script
>
<
script
type
=
"text/javascript"
>
$(function () {
//Calculate and update Grand Total.
var
grandTotal
=
0
;
$("[id*=lblProductTotal]").each(function () {
grandTotal
grandTotal
= grandTotal + parseFloat($(this).html());
});
$("[id*=txtTotal]").val(grandTotal.toString());
});
$(document).ready(function () {
$('#txtcustomer').keyboard({
autoAccept: true
})
.addTyping();
$('#txtqty').keyboard({
layout: 'num',
restrictInput: true,
preventPaste: true,
autoAccept: true
})
.addTyping();
$('#QTY').keyboard({
layout: 'num',
restrictInput: true,
preventPaste: true,
autoAccept: true
})
.addTyping();
});
</
script
>
<
head
runat
=
"server"
>
<
title
>
</
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
div
>
<
table
class
=
"auto-style1"
>
<
tr
>
<
td
>
<
div
>
<
asp:DataList
ID
=
"dlemp"
runat
=
"server"
RepeatDirection
=
"Horizontal"
RepeatColumns
=
"2"
>
<
ItemTemplate
>
<
div
id
=
"pricePlans"
>
<
ul
id
=
"plans"
>
<
li
class
=
"plan"
>
<
ul
class
=
"planContainer"
>
<
li
class
=
"title"
>
<
h2
>
<
asp:Label
ID
=
"ProductName"
runat
=
"server"
Text
=
'<%# Eval("Name") %>'
>
</
asp:Label
>
<
br
/>
</
li
>
<
li
class
=
"title"
>
<
asp:Image
ID
=
"imgEmp"
Height
=
"100px"
Width
=
"100px"
runat
=
"server"
ImageUrl
=
'<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>'
/>
</
li
>
<
li
>
<
ul
class
=
"options"
>
<
div
>
<
li
>
<
b
>
Id:
</
b
>
<
asp:Label
ID
=
"CustomerID"
runat
=
"server"
Text
=
' <%# Eval("Id") %>'
>
</
asp:Label
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
Text
=
"select"
OnCheckedChanged
=
"Redirect"
/>
<
asp:Button
ID
=
"btnadd"
runat
=
"server"
Text
=
"Add Cart"
OnClick
=
"AddToCart"
>
</
asp:Button
>
</
li
>
</
div
>
</
ul
>
</
li
>
</
ul
>
</
li
>
</
ul
>
</
div
>
</
div
>
</
ItemTemplate
>
<
FooterTemplate
>
</
FooterTemplate
>
</
asp:DataList
>
</
div
>
</
td
>
<
td
>
<
asp:GridView
ID
=
"GridView1"
runat
=
"server"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
asp:TemplateField
HeaderText
=
"Image"
>
<
ItemTemplate
>
<
asp:Image
ID
=
"Data"
runat
=
"server"
Width
=
"100px"
Height
=
"80px"
ImageUrl
=
'<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>'
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Name"
>
<
ItemTemplate
>
<
asp:Label
Text
=
'<%#Eval("Name") %>'
runat
=
"server"
ID
=
"lblName"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"QTY"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"txtqty"
onkeyup
=
"CalculateTotals();"
Text
=
'<%#Eval("txtqty") %>'
runat
=
"server"
Height
=
"16px"
Width
=
"33px"
>
</
asp:TextBox
>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Price"
>
<
ItemTemplate
>
<
asp:Label
Text
=
'<%#Eval("Price") %>'
runat
=
"server"
ID
=
"lblPrice"
/>
</
ItemTemplate
>
</
asp:TemplateField
>
<
asp:TemplateField
HeaderText
=
"Total"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblProductTotal"
runat
=
"server"
Text
=
'<%# ((Convert.ToInt32(Eval("txtqty")))*(Convert.ToInt32(Eval("Price"))))%>'
>
</
asp:Label
>
</
ItemTemplate
>
</
asp:TemplateField
>
</
Columns
>
</
asp:GridView
>
</
td
>
</
tr
>
<
tr
>
<
td
>
</
td
>
<
td
>
</
td
>
</
tr
>
</
table
>
</
div
>
</
div
>
</
form
>
</
body
>
</
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();
}
}
}
} }
Reply
Answers (
1
)
Create a List of Users(MVC Web Application)
json with ajax call in c#