Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 9-May-13 0:16am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Refer the below code for grid editing , deleteing
 

 
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();
    }
 
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100