Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to replace text boxes with label in gridview in edit mode in asp.net

i have table
like

id name Qty

entry has been made already
like

1 abc 45
2 def 35
3 erf 56

now i want that user can only modify Qty field so I need to replace textboxes of first two field should be with label.


please help me its urgent

thanx in advance
Posted

 
Share this answer
 
Generally in gridview template columns there are two templates, first one is Item Template and second one is EditItem template.

Generally what we do is to to keep lable in Item template and textboxes in EditItem template of every column (or some other control like dropdown or checkbox based on requirement).

In your case for all those columns which you don't want to be updated, keep label in both item as well as in EditItem template.

One more thing if your columns are not template column convert them.


Hope this will help.
 
Share this answer
 
Refer the below code for grid editing , deleteing


C#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int ID = (int)GridView1.DataKeys[e.RowIndex].Value;
        // Query the database and get the values based on the ID and delete it.
        lblMsg.Text = "Deleted Record Id" +ID.ToString();
      
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGrid();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       
        // Retrieve the row being edited.
        int index = GridView1.EditIndex;
        GridViewRow row = GridView1.Rows[index];
        TextBox t1 = row.FindControl("TextBox1") as TextBox;
        TextBox t2 = row.FindControl("TextBox2") as TextBox;
        string t3 = GridView1.DataKeys[e.RowIndex].Value.ToString();

        lblMsg.Text = "Updated record " + t1.Text + "," + t2.Text + "Value From Bound Field" + t3;
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindGrid();
    }
 
Share this answer
 

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