Click here to Skip to main content
11,642,855 members (70,799 online)
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 8-May-13 23:16pm
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 DamithSL 328
1 OriginalGriff 280
2 Sergey Alexandrovich Kryukov 270
3 Afzaal Ahmad Zeeshan 195
4 jyo.net 190
0 DamithSL 541
1 OriginalGriff 495
2 Mika Wendelius 469
3 Sergey Alexandrovich Kryukov 330
4 Afzaal Ahmad Zeeshan 324


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 9 May 2013
Copyright © CodeProject, 1999-2015
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