Member Avatar for spacepilot5000

Data entered in textboxes is not getting updated in database. In debug mode I see that textbox1 and textbox2 in ItemUpdating event contain the same values as they had before calling ItemUpdating.

Here's my listview control:

<asp:ListView ID="ListView1" runat="server"

//LayoutTemplate removed

      <asp:Label ID="Label2" runat="server" Text='<%#Eval("id")%>'></asp:Label>
      <asp:Label ID="Label3" runat="server" Text='<%#Eval("text1")%>'></asp:Label>

      <asp:LinkButton ID="LinkButton2" CommandName="Edit" runat="server">Edit</asp:LinkButton>
      <asp:LinkButton ID="LinkButton4" CommandName="Delete" runat="server">Delete</asp:LinkButton>
    <asp:Label ID="Label1" runat="server" Text='<%#Eval("id")%>'></asp:Label>
    <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("text1")%>' TextMode="MultiLine" />
    <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("text2")%>' Height="100" TextMode="MultiLine" />

    <asp:LinkButton ID="LinkButton1" CommandName="Update" CommandArgument='<%# Eval("id")%>' runat="server">Update</asp:LinkButton>
    <asp:LinkButton ID="LinkButton5" CommandName="Cancel" runat="server">Cancel</asp:LinkButton>
    <asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Height="100"></asp:TextBox>
    <asp:TextBox ID="TextBox4" runat="server" Height="100" TextMode="MultiLine"></asp:TextBox>

    <asp:LinkButton ID="LinkButton3" runat="server">Insert</asp:LinkButton>

Codebehind file:

protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
    ListView1.EditIndex = e.NewEditIndex;
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    ListViewItem myItem = ListView1.Items[ListView1.EditIndex];

    Label id = (Label)myItem.FindControl("Label1");
    int dbid = int.Parse(id.Text);

    TextBox text1 = (TextBox)myItem.FindControl("Textbox1");
    TextBox text2 = (TextBox)myItem.FindControl("Textbox2");

    //tried to work withNewValues below, but they don't work, "null reference" error is being thrown
    //text1.Text = e.NewValues["text1"].ToString();
    //text2.Text = e.NewValues["text2"].ToString();

    //odbc connection routine removed.
    //i know that there should be odbc parameteres:
    comm = new OdbcCommand("UPDATE table SET text1 = '" + text1.Text + "', text2 = '" + text2.Text + "' WHERE id = '" + dbid + "'", connection);


    ListView1.EditIndex = -1;
    //here I databind ListView1

What's wrong with updating of text1.Text, text2.Text in ItemUpdating event? Should I use e.NewValues property? If so, how to use it?

Thanks in advance for any help.

Recommended Answers

All 6 Replies

i also encounter problem like u, up to now i have not still found solution, if anybody know solution for this problem, send me your solution please. my email is [snipped]. Thanks everyboy.

Member Avatar for spacepilot5000

I found out that I forgot to use to use in Page_Load():

if (!IsPostBack) 
        ListView1.DataSource = ds;

cool .. :)

I think u should provide DataKeyNames property of ListView.

thanks everybody, thanks lurii, you're right, this is solution for this problem.
thanks everybody agains, hihi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.