Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am working with ASP C# ListView, i have dragged and dropped it and bind it to my datasource(database). The problem is, i am populating Listview with a single row, as in a row consist of, ID, email, profession and other details. When a user logins he is able to view Data against his email. (i.e. only one row).

I am able to Update the data, but i want to provide seperate update/edit buttons against each cell in a row. I am unable to do it! i have tried adding asp edit buttons in EditItem templete but m still confused. How to do it? Heres my code (webform):

C#
<EditItemTemplate>
<span style="background-color: #FFCC66; color: #000080;">ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
<br />
name:
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<br />
<asp:Button ID="edito" runat="server" OnClick="UpdateButton_Click" />
gender:
<asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>' />
<br />

Email:
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />

<asp:Button ID="UpdateButton" runat="server" 
    Text="Update" OnClick="UpdateButton_Click"  />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
    Text="Cancel" />
</span>
</EditItemTemplate>

Here's my code .cs:
C#
protected void UpdateButton_Click(object sender, EventArgs e)
{
    TextBox nam=(TextBox) ListView1.EditItem.FindControl("nameTextBox");
    nam.Text = name;


    string email = (string)(Session["email"]) ;


    try
    {
        SqlConnection connection = getConnection();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connection;

        cmd.CommandText = ("UPDATE [profile] SET name=@name WHERE Email LIKE @email ");

        cmd.Parameters.AddWithValue("@name", name);
        cmd.Parameters.AddWithValue("email", SqlDbType.Text).Value= email;


        cmd.ExecuteNonQuery();

        connection.Close();
}....

i have added the button edito above, but the thing is, i want user to select the value to be updated and only that should be shown in textbox as editable text. Not all the Fields should be shown as editing fields( which is the default behavior of LISTVIEW when we view it as EditTemplete view, only one single Edit button is available which turns all values as textfields). Kindly Help!
Posted
Updated 27-May-13 18:32pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900