473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

LinqDataSource/ ListView - Inserts Returning No Values To Insert

I am attempting to insert a simple record with LinqDataSource from a
ListView, however I always get a message saying "....LinqDataSource
'dataSource' has no values to insert. Check that the 'values' dictionary
contains values...."

I am using a ListView with a DataSourceID of a LinqDataSource. When a new
row icon is clicked....the ListView properly enters into the
InsertItemTemplate....however when the ImageButton with a CommandName of
"Update" is clicked....the above message is displayed. Data is properly
being bound, etc.

I have a simple project which reproduces the problem.

Please offer suggestions on what you think the problem is.

The C# source code is as follows...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnNewRow_Click(object sender, EventArgs e)
{
lvwList.EditIndex = -1;
lvwList.InsertItemPosition = InsertItemPosition.FirstItem;
}
}

ASPX file is as follows....
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ListView Insert Problem</title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 100px; margin-top: 100px;">
<asp:ListView ID="lvwList"
DataSourceID="dataSource"
DataKeyNames="AdvertiserCategory"
runat="server">
<LayoutTemplate>
<asp:ImageButton ID="btnNewRow" runat="server"
CausesValidation="False"
OnClick="btnNewRow_Click"
ImageUrl="~/images/VSNet2008Actions/NewDocumentHS.png" />
<table runat="server"
cellspacing="0"
border="0">
<tr>
<th></th>
<th></th>
<th>Category</th>
<th>Description</th>
</tr>

<tr runat="server" id="itemPlaceholder" />

</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:ImageButton runat="server"
CausesValidation="False"
CommandName="Edit"
ImageUrl="~/images/VSNet2008Actions/EditInformationHS.png" />
</td>
<td align="center">
<asp:ImageButton runat="server"
OnClientClick='showConfirm(this); return false;'
CausesValidation="False"
CommandName="Delete"
ImageUrl="~/images/VSNet2008Actions/DeleteHS.png" />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategoryDesc") %>'
/>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Update"
Text="Update"
style="margin-left: 2px;"
ToolTip="Click to Save Editing..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:Label ID="lblAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</EditItemTemplate>
<InsertItemTemplate>
<tr runat="server">
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Insert"
Text="Insert"
style="margin-left: 2px;"
ToolTip="Click to Insert New Item..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>'
Width="150px" />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="dataSource" runat="server"
ContextTypeName="SLCMS_DB_DataContext"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True"
TableName="SLCMS_AdvertiserCategories">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>

--
Philip
Jul 22 '08 #1
2 3346
I meant to say a CommandName of "Insert"....not "Update".... which is obvious
from the source code below.

Any help is greatly appreciated.... I have wasted many hours already.

--
Philip
"Philip" wrote:
I am attempting to insert a simple record with LinqDataSource from a
ListView, however I always get a message saying "....LinqDataSource
'dataSource' has no values to insert. Check that the 'values' dictionary
contains values...."

I am using a ListView with a DataSourceID of a LinqDataSource. When a new
row icon is clicked....the ListView properly enters into the
InsertItemTemplate....however when the ImageButton with a CommandName of
"Update" is clicked....the above message is displayed. Data is properly
being bound, etc.

I have a simple project which reproduces the problem.

Please offer suggestions on what you think the problem is.

The C# source code is as follows...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnNewRow_Click(object sender, EventArgs e)
{
lvwList.EditIndex = -1;
lvwList.InsertItemPosition = InsertItemPosition.FirstItem;
}
}

ASPX file is as follows....
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ListView Insert Problem</title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 100px; margin-top: 100px;">
<asp:ListView ID="lvwList"
DataSourceID="dataSource"
DataKeyNames="AdvertiserCategory"
runat="server">
<LayoutTemplate>
<asp:ImageButton ID="btnNewRow" runat="server"
CausesValidation="False"
OnClick="btnNewRow_Click"
ImageUrl="~/images/VSNet2008Actions/NewDocumentHS.png" />
<table runat="server"
cellspacing="0"
border="0">
<tr>
<th></th>
<th></th>
<th>Category</th>
<th>Description</th>
</tr>

<tr runat="server" id="itemPlaceholder" />

</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:ImageButton runat="server"
CausesValidation="False"
CommandName="Edit"
ImageUrl="~/images/VSNet2008Actions/EditInformationHS.png" />
</td>
<td align="center">
<asp:ImageButton runat="server"
OnClientClick='showConfirm(this); return false;'
CausesValidation="False"
CommandName="Delete"
ImageUrl="~/images/VSNet2008Actions/DeleteHS.png" />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategoryDesc") %>'
/>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Update"
Text="Update"
style="margin-left: 2px;"
ToolTip="Click to Save Editing..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:Label ID="lblAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</EditItemTemplate>
<InsertItemTemplate>
<tr runat="server">
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Insert"
Text="Insert"
style="margin-left: 2px;"
ToolTip="Click to Insert New Item..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>'
Width="150px" />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="dataSource" runat="server"
ContextTypeName="SLCMS_DB_DataContext"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True"
TableName="SLCMS_AdvertiserCategories">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>

--
Philip
Jul 22 '08 #2
I have found the problem.

The runat="server" on the <tr tag ....1st statement within the
InsertItemTemplate is causing the problem. Remove the runat="server" and
everything works fine.

Please shed some light on why this should cause a problem.

--
Philip
"Philip" wrote:
I meant to say a CommandName of "Insert"....not "Update".... which is obvious
from the source code below.

Any help is greatly appreciated.... I have wasted many hours already.

--
Philip
"Philip" wrote:
I am attempting to insert a simple record with LinqDataSource from a
ListView, however I always get a message saying "....LinqDataSource
'dataSource' has no values to insert. Check that the 'values' dictionary
contains values...."

I am using a ListView with a DataSourceID of a LinqDataSource. When a new
row icon is clicked....the ListView properly enters into the
InsertItemTemplate....however when the ImageButton with a CommandName of
"Update" is clicked....the above message is displayed. Data is properly
being bound, etc.

I have a simple project which reproduces the problem.

Please offer suggestions on what you think the problem is.

The C# source code is as follows...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnNewRow_Click(object sender, EventArgs e)
{
lvwList.EditIndex = -1;
lvwList.InsertItemPosition = InsertItemPosition.FirstItem;
}
}

ASPX file is as follows....
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ListView Insert Problem</title>
</head>
<body>
<form id="form1" runat="server">
<div style="margin-left: 100px; margin-top: 100px;">
<asp:ListView ID="lvwList"
DataSourceID="dataSource"
DataKeyNames="AdvertiserCategory"
runat="server">
<LayoutTemplate>
<asp:ImageButton ID="btnNewRow" runat="server"
CausesValidation="False"
OnClick="btnNewRow_Click"
ImageUrl="~/images/VSNet2008Actions/NewDocumentHS.png" />
<table runat="server"
cellspacing="0"
border="0">
<tr>
<th></th>
<th></th>
<th>Category</th>
<th>Description</th>
</tr>

<tr runat="server" id="itemPlaceholder" />

</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td align="center">
<asp:ImageButton runat="server"
CausesValidation="False"
CommandName="Edit"
ImageUrl="~/images/VSNet2008Actions/EditInformationHS.png" />
</td>
<td align="center">
<asp:ImageButton runat="server"
OnClientClick='showConfirm(this); return false;'
CausesValidation="False"
CommandName="Delete"
ImageUrl="~/images/VSNet2008Actions/DeleteHS.png" />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:Label runat="server" Text='<%# Eval("AdvertiserCategoryDesc") %>'
/>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Update"
Text="Update"
style="margin-left: 2px;"
ToolTip="Click to Save Editing..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:Label ID="lblAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>' />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</EditItemTemplate>
<InsertItemTemplate>
<tr runat="server">
<td colspan="2">
<asp:LinkButton runat="server"
CausesValidation="True"
CommandName="Insert"
Text="Insert"
style="margin-left: 2px;"
ToolTip="Click to Insert New Item..."/>
<asp:LinkButton runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel"
style="margin-left: 5px; margin-right: 2px;"
ToolTip="Click to Cancel..." />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategory" runat="server"
Text='<%# Bind("AdvertiserCategory") %>'
Width="150px" />
</td>
<td align="left">
<asp:TextBox ID="txtAdvertiserCategoryDesc" runat="server"
Text='<%# Bind("AdvertiserCategoryDesc") %>'
Width="250px" />
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="dataSource" runat="server"
ContextTypeName="SLCMS_DB_DataContext"
EnableDelete="True"
EnableInsert="True"
EnableUpdate="True"
TableName="SLCMS_AdvertiserCategories">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>

--
Philip
Jul 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Stadler | last post by:
Using mysql 4.0.23- What is the best way to execute several (hundreds of) inserts and updates? Rather than issuing tons of individual inserts and updates, can I send the strings to a text file...
5
by: Humble Geek | last post by:
Hi all. Quick and perhaps silly question, but... I am using Pg 7.3. I am writing a function using pgplsql. This function will perform multiple inserts. Let's say two of the inserts are as...
5
by: Florence HENRY | last post by:
Hello, well, almost everything is in the subject ! I have to fill 2 tables (more complicated than in the example !): CREATE TABLE A ( id serial primary key, foo text);
3
by: geoff | last post by:
I have a table called 'employee' with one column called 'name', a varchar. If I execute the following insert statements: insert into employee(name) values ('jones') insert into employee(name)...
0
by: =?Utf-8?B?UmFzbXVz?= | last post by:
I have a simple LiveView control that databinds to a LinqDataSource that maps to a table like this: CREATE TABLE MyTable (Id int NOT NULL, Name nvarchar(50) NULL, Picture image NULL) The OR...
1
by: shapper | last post by:
Hello, I have a ListView connected to a LinqDataSource. It uses a table, named Tags, with 2 fields: TagId and Text. I need to add a column named active. For this I created a LinqDataSource...
0
by: Marius Manolea | last post by:
Hi, I have a strange problem, I don't receive any modifications from listview in edit mode (OldValues & NewValues are empty) <asp:ListView ID="lvEditPersonRoles" runat="server"...
0
by: Andy B | last post by:
I have a GridView with a LINQDataSource attached to it. My code in the aspx markup is below. I need to know why only the checkbox field for the activated column is getting updated (the...
2
by: mesut | last post by:
Hi colleagues, how can I configure a linqdatasource in code behind. I mean I would like to create the linqdatasource programmatically in the code behind rather then dropping from the toolbox. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.