Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > listview insert question

Reply
Thread Tools

listview insert question

 
 
JohnE
Guest
Posts: n/a
 
      05-29-2010
I am really having a time determining what is wrong with the inserting from a
dropdownlist inside a listview. Everything else is working regarding the
listview, except the insert. But, there must partially working as there is a
new row added to the table, just not with information. When I add

SelectedValue='<%# Bind("ApplicationItemID") %>'

to the droplist I get an error. The error is as follows;

"Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control."

I have an insertcommand and parameters in the sqldatasource. It is as
follows;

InsertCommand="INSERT INTO tblApplication (ApplicationItemID,
ChangeRequestID) VALUES (@applicationitemid, @changerequestid)" >

<InsertParameters>
<asparameter Name="ApplicationItemID" Type="Int32" />
<asparameter Name="ChangeRequestID" Type="Int32" />
</InsertParameters>

Here also is the InsertItemTemplate info;

<InsertItemTemplate>
<tr runat="server">
<td><asp:Label
ID="lblApplicationIDEditLabel" runat="server"><%# Eval("ApplicationID")
%></asp:Label></td>
<td>
<aspropDownList
ID="ddlApplicationItemIDInsertEdit" runat="server"

DataSourceID="ApplicationItemInsertSqlDataSource"

DataTextField="ApplicationItem"

DataValueField="ApplicationItemID" >
</aspropDownList>
</td>
<td><asp:Label
ID="lblChangeRequestIDLabel" runat="server"><%# Eval("ChangeRequestID")
%></asp:Label></td>
<td><asp:LinkButton ID="lbtnInsert"
runat="server" CommandName="Insert" Text="Insert"></asp:LinkButton></td>
</tr>
</InsertItemTemplate>

I have tried code behind for the drop list as well as the item command. I
am also enclosing that info as well.

protected void lvwApplicationItem_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
DropDownList ddlApplicationItemIDInsertEdit =
(DropDownList)e.Item.FindControl("ddlApplicationIt emIDInsertEdit");
Label ChangeRequestIDLabel =
(Label)e.Item.FindControl("ChangeRequestIDLabel");
string insertCommand = "INSERT INTO [tblApplication]
([ApplicationItemID], [ChangeRequestID]) VALUES
(ddlApplicationItemIDInsertEdit, ChangeRequestIDLabel)";
DetailApplicationEditSqlDataSource.InsertCommand = insertCommand;

}
}

protected void lvwApplicationItem_ItemInserting(object sender,
ListViewInsertEventArgs e)
{
DropDownList ddlApplicationItemIDInsertEdit =
(DropDownList)e.Item.FindControl("ddlApplicationIt emIDInsertEdit");

if (ddlApplicationItemIDInsertEdit != null)
{
e.Values["ApplicationItemID"] =
(Convert.ToInt32(ddlApplicationItemIDInsertEdit.Se lectedValue));
}
}


I am getting frustrated over this and ask if someone would look this over
and see what, where, how, and why the insert is not working. If further info
is need, please let me know.

Thanks....John





 
Reply With Quote
 
 
 
 
JohnE
Guest
Posts: n/a
 
      05-29-2010
Stupid me. I was forgetting to add the oniteminserting to the listview.
Thank goodness for 3 day weekends.
John


"JohnE" wrote:

> I am really having a time determining what is wrong with the inserting from a
> dropdownlist inside a listview. Everything else is working regarding the
> listview, except the insert. But, there must partially working as there is a
> new row added to the table, just not with information. When I add
>
> SelectedValue='<%# Bind("ApplicationItemID") %>'
>
> to the droplist I get an error. The error is as follows;
>
> "Databinding methods such as Eval(), XPath(), and Bind() can only be used in
> the context of a databound control."
>
> I have an insertcommand and parameters in the sqldatasource. It is as
> follows;
>
> InsertCommand="INSERT INTO tblApplication (ApplicationItemID,
> ChangeRequestID) VALUES (@applicationitemid, @changerequestid)" >
>
> <InsertParameters>
> <asparameter Name="ApplicationItemID" Type="Int32" />
> <asparameter Name="ChangeRequestID" Type="Int32" />
> </InsertParameters>
>
> Here also is the InsertItemTemplate info;
>
> <InsertItemTemplate>
> <tr runat="server">
> <td><asp:Label
> ID="lblApplicationIDEditLabel" runat="server"><%# Eval("ApplicationID")
> %></asp:Label></td>
> <td>
> <aspropDownList
> ID="ddlApplicationItemIDInsertEdit" runat="server"
>
> DataSourceID="ApplicationItemInsertSqlDataSource"
>
> DataTextField="ApplicationItem"
>
> DataValueField="ApplicationItemID" >
> </aspropDownList>
> </td>
> <td><asp:Label
> ID="lblChangeRequestIDLabel" runat="server"><%# Eval("ChangeRequestID")
> %></asp:Label></td>
> <td><asp:LinkButton ID="lbtnInsert"
> runat="server" CommandName="Insert" Text="Insert"></asp:LinkButton></td>
> </tr>
> </InsertItemTemplate>
>
> I have tried code behind for the drop list as well as the item command. I
> am also enclosing that info as well.
>
> protected void lvwApplicationItem_ItemCommand(object sender,
> ListViewCommandEventArgs e)
> {
> if (e.CommandName == "Insert")
> {
> DropDownList ddlApplicationItemIDInsertEdit =
> (DropDownList)e.Item.FindControl("ddlApplicationIt emIDInsertEdit");
> Label ChangeRequestIDLabel =
> (Label)e.Item.FindControl("ChangeRequestIDLabel");
> string insertCommand = "INSERT INTO [tblApplication]
> ([ApplicationItemID], [ChangeRequestID]) VALUES
> (ddlApplicationItemIDInsertEdit, ChangeRequestIDLabel)";
> DetailApplicationEditSqlDataSource.InsertCommand = insertCommand;
>
> }
> }
>
> protected void lvwApplicationItem_ItemInserting(object sender,
> ListViewInsertEventArgs e)
> {
> DropDownList ddlApplicationItemIDInsertEdit =
> (DropDownList)e.Item.FindControl("ddlApplicationIt emIDInsertEdit");
>
> if (ddlApplicationItemIDInsertEdit != null)
> {
> e.Values["ApplicationItemID"] =
> (Convert.ToInt32(ddlApplicationItemIDInsertEdit.Se lectedValue));
> }
> }
>
>
> I am getting frustrated over this and ask if someone would look this over
> and see what, where, how, and why the insert is not working. If further info
> is need, please let me know.
>
> Thanks....John
>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net ListView control - Configure ListView option missing? . ASP .Net 0 07-24-2010 12:20 AM
Insert Button. ListView or GridView. Is this possible? shapper ASP .Net 4 11-20-2008 09:39 AM
LinqDataSource/ ListView - Inserts Returning No Values To Insert Philip ASP .Net 2 07-23-2008 12:49 AM
Update and Insert problems in ListView shapper ASP .Net 1 02-12-2008 12:46 AM
ListView ... Update and Insert shapper ASP .Net 0 02-08-2008 04:02 PM



Advertisments