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>
<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("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
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("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