473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

editable gridview

i want editable gridview in C# vs2005.i want a column get added to gridview with edit button. once i click on edit button at runtime,all cells shud become textbox and edit should be replaced by update and cancel option

plz help its urgent....i searched on net but i m not getting. i dont want coding in xml file.i want steps to be followed at front end using visual studio.


plz help
thnx in advance
Mar 28 '08 #1
6 2176
vee10
141 100+
Hi ,

this is the sample example u can save and fill data using database

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml" >
  7. <head runat="server">
  8.     <title>Untitled Page</title>
  9. </head>
  10. <body>
  11.     <form id="form1" runat="server">
  12.     <div>
  13.     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  OnRowCancelingEdit="GridView1_RowCancelingEdit"  OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"> 
  14. <Columns> 
  15. <asp:TemplateField HeaderText="Edit" ShowHeader="False"> 
  16. <EditItemTemplate> 
  17.   <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
  18.   <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
  19. </EditItemTemplate> 
  20.  
  21. <ItemTemplate> 
  22.   <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> 
  23. </ItemTemplate> 
  24. </asp:TemplateField> 
  25. <asp:TemplateField HeaderText="WTTPath" SortExpression="Name"> <EditItemTemplate> 
  26.   <asp:TextBox ID="txtWTTPath" runat="server" Text='<%# Eval("WTTPath") %>'></asp:TextBox> 
  27. </EditItemTemplate> 
  28. <ItemTemplate> 
  29.   <asp:Label ID="Label2" runat="server" Text='<%# Bind("WTTPath") %>'></asp:Label> 
  30. </ItemTemplate> 
  31. </asp:TemplateField> 
  32.  
  33. <asp:TemplateField HeaderText="PSPath"> 
  34. <EditItemTemplate> 
  35.   <asp:TextBox ID="txtPSPath" runat="server" Text='<%# Bind("PSPath") %>'></asp:TextBox> 
  36. </EditItemTemplate> 
  37.  
  38. <ItemTemplate> 
  39.   <asp:Label ID="Label3" runat="server" Text='<%# Bind("PSPath") %>'></asp:Label> 
  40. </ItemTemplate> 
  41. </asp:TemplateField> 
  42. </Columns> 
  43. </asp:GridView> 
  44.     </div>    
  45.     </form>
  46. </body>
  47. </html>
  48.  
  49. page load event
  50.  
  51. using System;
  52. using System.Data;
  53. using System.Configuration;
  54. using System.Collections;
  55. using System.Web;
  56. using System.Web.Security;
  57. using System.Web.UI;
  58. using System.Web.UI.WebControls;
  59. using System.Web.UI.WebControls.WebParts;
  60. using System.Web.UI.HtmlControls;
  61.  
  62. public partial class Default8 : System.Web.UI.Page
  63. {
  64.     protected void Page_Load(object sender, EventArgs e)
  65.     {
  66.         DataTable dt = new DataTable("ComponentTable");
  67.         DataRow dr = dt.NewRow();
  68.         DataColumn dc = new DataColumn("WTTPath");
  69.         dc.DataType = Type.GetType("System.String");
  70.         dt.Columns.Add(dc);
  71.         dc = new DataColumn("PSPath");
  72.         dc.DataType = Type.GetType("System.String");
  73.         dt.Columns.Add(dc);
  74.         dr["WTTPath"] = "WTTPath";
  75.         dr["PSpath"] = "PSpath";
  76.         dt.Rows.Add(dr);
  77.         GridView1.DataSource = dt;
  78.         GridView1.DataBind(); 
  79.     }
  80.  
  81.     protected void FillData()
  82.     {
  83.         DataTable dt = new DataTable("ComponentTable");
  84.         DataRow dr = dt.NewRow();
  85.         DataColumn dc = new DataColumn("WTTPath");
  86.         dc.DataType = Type.GetType("System.String");
  87.         dt.Columns.Add(dc);
  88.         dc = new DataColumn("PSPath");
  89.         dc.DataType = Type.GetType("System.String");
  90.         dt.Columns.Add(dc);
  91.         dr["WTTPath"] = "WTTPath"; //u should fill data using database not directly assigning like this
  92.         dr["PSpath"] = "PSpath";
  93.         dt.Rows.Add(dr);
  94.         GridView1.DataSource = dt;
  95.         GridView1.DataBind(); 
  96.     }
  97.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  98.     {
  99.         GridView1.EditIndex = e.NewEditIndex;
  100.         FillData();
  101.     }
  102.     protected void GridView1_RowCommand(object sender, EventArgs e)
  103.     {
  104.     }
  105.     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  106.     {
  107.         TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtWTTPath");        
  108.         TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtPSPath");
  109.         //write logic what ever u want  ie save this in database
  110.  
  111.         FillData();
  112.         GridView1.EditIndex = -1;
  113.  
  114.     } 
  115.     protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  116.     {
  117.         GridView1.EditIndex = -1;
  118.  
  119.     }
  120.  
  121. }
  122.  
  123.  
  124.  
any doubts u can query
Mar 28 '08 #2
plz tell me steps to add edit-column in gridview in design view....i m not much thorough with xml...........i mean setting some property of gridvew(edit command or something) and then writing on rowediting event............i can write code for update .........problem is i m not able to add that edit column in gridview.........plz tell steps ....setting properties or using smart tag of gridview

plz do reply.having interview 2moro
Mar 28 '08 #3
vee10
141 100+
hi ,

Step 1: Adding edit - column in Gridview
in Grid view click "Add New Colums" then a popup will be opened and
select "CommandField" then click checkboxes Edit/Update and click "ok"

Step 2:
in Grid view click "Edit column" and then a popup will open and then click "Convert this into Template field" and click ok

Step3:
in grid view click "Edit Templates" a popup will open select "Edit Item Template"
and place textboxes in to that and click Edit bindings and then for Text
give Code Expression as "Bind("name of the column") and click "OK"

write the rowupdating ,rowcanceling,rowediting functions

Any doubt ask me





plz tell me steps to add edit-column in gridview in design view....i m not much thorough with xml...........i mean setting some property of gridvew(edit command or something) and then writing on rowediting event............i can write code for update .........problem is i m not able to add that edit column in gridview.........plz tell steps ....setting properties or using smart tag of gridview

plz do reply.having interview 2moro
Mar 28 '08 #4
hi ,

Step 1: Adding edit - column in Gridview
in Grid view click "Add New Colums" then a popup will be opened and
select "CommandField" then click checkboxes Edit/Update and click "ok"

Step 2:
in Grid view click "Edit column" and then a popup will open and then click "Convert this into Template field" and click ok

Step3:
in grid view click "Edit Templates" a popup will open select "Edit Item Template"
and place textboxes in to that and click Edit bindings and then for Text
give Code Expression as "Bind("name of the column") and click "OK"

write the rowupdating ,rowcanceling,rowediting functions

Any doubt ask me
thnx for ur reply..
actually prob is i m confused withedtitemtemplate n itemtemplate in html source file.
can u tell what is purpose of both of these. can u explain sequence of steps occurs when i click a row to edit. wh happens inside.plz help
May 7 '08 #5
vee10
141 100+
Item Template is nothing but adding any linkbutton or textbox etc ie ading any single item control

EditItem Template is adding some controls when we click the Edit button in the datagrid only these controls will be available after clicking edit in datagrid
but in itemTemplate when the datagrid is loaded this will be available ie we can see the controls under <ITEMTEMPLATE> once datagrid is loaded
but for <EDITITEMTEMPLATE> u can see only when u click the edit button
just once try the above example or check this

http://www.morpheusweb.it/html/scrip...latecolumn.asp

then u can understand the difference b/w that

check the example and check these steps

steps when u click the edit:

1.After clicking edit the Update and Cancel link wil be available in the datagrid in that edit cell and all other cells will be converted to the Textboxes or dropdown box or checkbox according to the values or ur requirement (these will be written in the <edititemtemplate>)

2.then u can update ur cells and once u click Update then OnRowUpdating event is fired so u should write ur logic for that event ie placing it in database etc

3.U update the cells but u clicked cancel then OnRowCancelling is fired so the correspoing logic for that event



thnx for ur reply..
actually prob is i m confused withedtitemtemplate n itemtemplate in html source file.
can u tell what is purpose of both of these. can u explain sequence of steps occurs when i click a row to edit. wh happens inside.plz help
May 8 '08 #6
Item Template is nothing but adding any linkbutton or textbox etc ie ading any single item control

EditItem Template is adding some controls when we click the Edit button in the datagrid only these controls will be available after clicking edit in datagrid
but in itemTemplate when the datagrid is loaded this will be available ie we can see the controls under <ITEMTEMPLATE> once datagrid is loaded
but for <EDITITEMTEMPLATE> u can see only when u click the edit button
just once try the above example or check this

http://www.morpheusweb.it/html/scrip...latecolumn.asp

then u can understand the difference b/w that

check the example and check these steps

steps when u click the edit:

1.After clicking edit the Update and Cancel link wil be available in the datagrid in that edit cell and all other cells will be converted to the Textboxes or dropdown box or checkbox according to the values or ur requirement (these will be written in the <edititemtemplate>)

2.then u can update ur cells and once u click Update then OnRowUpdating event is fired so u should write ur logic for that event ie placing it in database etc

3.U update the cells but u clicked cancel then OnRowCancelling is fired so the correspoing logic for that event
thank u so much for this detail explanation.Currently i m doing other project.i will check this soon.thnx once again
May 9 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: SDRoy | last post by:
Hi Can someone help me to figure out how to get the editable textbox value from GridView in my code-behind ? I am using the code something like- GridView2.Rows.Cells.Text.Trim(). But when I...
3
by: Mike P | last post by:
Is it possible to make an editable gridview so that certain rows are editable and other are not editable, dependent upon a value in one of the rows columns? *** Sent via Developersdex...
2
by: dba56 | last post by:
In an ASP.Net 2.0 page using SQL Server 2K, I have a editable gridview that is bound to a SQLDataSource using stored procedures for its select and update queries. The grid works fine but is slow...
1
by: ad | last post by:
Hi, We can set a GridView editable or deleteable in desgin time. How can I set them in run time?
0
by: Frank | last post by:
Hello All, I am working with VS.NET 2005 and I have an editable GridView whose HTML markup is shown below. In short, when the user clicks on the Edit button, one of the textboxes is replaced...
0
by: Frank | last post by:
Hello All, I am working with VS.NET 2005 and I have an editable GridView whose HTML markup is shown below. In short, when the user clicks on the Edit button, one of the textboxes is replaced...
1
by: news-server.maine.rr.com | last post by:
Hi, I have the following bound to a database column and want the URL field to be editable in the GridView control. When the "Edit" link is clicked the field remains readOnly. ...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: Benny J | last post by:
Hello, I'm trying to implement 'Excel-like' hierarchial Editable GridView using nested Grids. When hierarchy is opened e.g. a row and it's child row I would like to align columns and edit...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.