listview insert question

Discussion in 'ASP .Net' started by JohnE, May 29, 2010.

  1. JohnE

    JohnE Guest

    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
     
    JohnE, May 29, 2010
    #1
    1. Advertising

  2. JohnE

    JohnE Guest

    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>
    > <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
    >
    >
    >
    >
    >
     
    JohnE, May 29, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shapper
    Replies:
    4
    Views:
    10,475
    David
    Nov 20, 2008
  2. shapper

    ListView ... Update and Insert

    shapper, Feb 8, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    1,171
    shapper
    Feb 8, 2008
  3. shapper
    Replies:
    1
    Views:
    699
    shapper
    Feb 12, 2008
  4. Philip
    Replies:
    2
    Views:
    730
    Philip
    Jul 23, 2008
  5. .
    Replies:
    0
    Views:
    745
Loading...

Share This Page