P
Philip
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>
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>