listview insert question

J

JohnE

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>
<asp:parameter Name="ApplicationItemID" Type="Int32" />
<asp:parameter 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>
<asp:DropDownList
ID="ddlApplicationItemIDInsertEdit" runat="server"

DataSourceID="ApplicationItemInsertSqlDataSource"

DataTextField="ApplicationItem"

DataValueField="ApplicationItemID" >
</asp:DropDownList>
</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("ddlApplicationItemIDInsertEdit");
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("ddlApplicationItemIDInsertEdit");

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


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
 
J

JohnE

Stupid me. I was forgetting to add the oniteminserting to the listview.
Thank goodness for 3 day weekends.
John


JohnE said:
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>
<asp:parameter Name="ApplicationItemID" Type="Int32" />
<asp:parameter 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>
<asp:DropDownList
ID="ddlApplicationItemIDInsertEdit" runat="server"

DataSourceID="ApplicationItemInsertSqlDataSource"

DataTextField="ApplicationItem"

DataValueField="ApplicationItemID" >
</asp:DropDownList>
</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("ddlApplicationItemIDInsertEdit");
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("ddlApplicationItemIDInsertEdit");

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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,188
Members
46,755
Latest member
HudsonP082

Latest Threads

Top