Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to make a gridview editable [modified]

how to make a gridview editable [modified]

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasegraphicshelp
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashutosh_karna
    wrote on last edited by
    #1

    I made a simple gridview in asp.net using the code written below. Now I want to make it editable so that at run time user can enter some data. Also,I dont want to put a thing like "edit button" ,i.e a user can simply edit a cell as he does in an excel spreadsheet. Can anybody tell me which event make the gridview editable ( I am not using any database) ? If possible, please give some code to help me understand. protected void Page_Load(object sender, EventArgs e) { dt = new DataTable(); Char[] alpha = { '#', 'A', 'B', 'C', 'D', 'E'}; for (int i = 0; i < alpha.Length; i++) { dt.Columns.Add(alpha[i].ToString()); } for (int i = 0; i < 1000; i++) { DataRow dr = dt.NewRow(); dr[0] = i + 1; dt.Rows.Add(dr); } GridView1.BorderColor = System.Drawing.Color.FromArgb(0, 0, 0); GridView1.DataSource = dt; GridView1.DataBind(); }

    modified on Saturday, June 6, 2009 3:56 PM

    M 1 Reply Last reply
    0
    • A ashutosh_karna

      I made a simple gridview in asp.net using the code written below. Now I want to make it editable so that at run time user can enter some data. Also,I dont want to put a thing like "edit button" ,i.e a user can simply edit a cell as he does in an excel spreadsheet. Can anybody tell me which event make the gridview editable ( I am not using any database) ? If possible, please give some code to help me understand. protected void Page_Load(object sender, EventArgs e) { dt = new DataTable(); Char[] alpha = { '#', 'A', 'B', 'C', 'D', 'E'}; for (int i = 0; i < alpha.Length; i++) { dt.Columns.Add(alpha[i].ToString()); } for (int i = 0; i < 1000; i++) { DataRow dr = dt.NewRow(); dr[0] = i + 1; dt.Rows.Add(dr); } GridView1.BorderColor = System.Drawing.Color.FromArgb(0, 0, 0); GridView1.DataSource = dt; GridView1.DataBind(); }

      modified on Saturday, June 6, 2009 3:56 PM

      M Offline
      M Offline
      Manoranjan Sahoo
      wrote on last edited by
      #2

      Create one gridview with all template field and set textbox for that template field when it displays the data it will display in textbox so that you can edit those field without click edit button. Then you can access those textbox value when you click on a button. Look at the following code to do so...

      <asp:GridView ID="GridView1" runat="server" Style="z-index: 106; left: 93px; position: absolute;
      top: 283px" Width="575px" EditIndex="1" AutoGenerateColumns="False">
      <Columns>
      asp:TemplateField
      <ItemTemplate>
      <asp:TextBox ID="txt1" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("slNo") %>'
      AutoPostBack ="false" TabIndex ="0" Width="25px" Height ="15px" Visible ="true" ></asp:TextBox>
      </ItemTemplate>
      </asp:TemplateField>
      asp:TemplateField
      <ItemTemplate>
      <asp:TextBox ID="txt2" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("Name") %>'
      AutoPostBack ="false" TabIndex ="0" Width="250px" Height ="15px" Visible ="true" ></asp:TextBox>
      </ItemTemplate>
      </asp:TemplateField>
      asp:TemplateField
      <ItemTemplate>
      <asp:TextBox ID="txt3" runat="server" MaxLength="3" Style="position: static" CssClass ="gv" text = '<%# Eval("Address") %>'
      AutoPostBack ="false" TabIndex ="0" Width="150px" Height ="15px" Visible ="true" ></asp:TextBox>
      </ItemTemplate>
      </asp:TemplateField>

      Then Place the following code in the button click event

      for (int i = 0; i

      after this you can use that string value to store into database or do further process.

      Manoranjan Sahoo
      Vist My Blog : Manoranjan's Blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups