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. Editable GridView

Editable GridView

Scheduled Pinned Locked Moved ASP.NET
helpsysadminquestion
7 Posts 4 Posters 0 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.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:

    <asp:TemplateField HeaderText="החל מ-">
    <EditItemTemplate>
    <asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
    <ItemTemplate>
    <asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
    </asp:TemplateField>

    I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event - TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart"); but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?

    N Steve EcholsS M 3 Replies Last reply
    0
    • T treuveni

      Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:

      <asp:TemplateField HeaderText="החל מ-">
      <EditItemTemplate>
      <asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
      <FooterTemplate>
      <asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
      <ItemTemplate>
      <asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
      </asp:TemplateField>

      I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event - TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart"); but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Have you debugged it? I would more than likely handle this on the client-side with some JavaScript.


      I know the language. I've read a book. - _Madmatt

      T 1 Reply Last reply
      0
      • N Not Active

        Have you debugged it? I would more than likely handle this on the client-side with some JavaScript.


        I know the language. I've read a book. - _Madmatt

        T Offline
        T Offline
        treuveni
        wrote on last edited by
        #3

        Mark Nischalke wrote:

        I would more than likely handle this on the client-side with some JavaScript.

        What you suggest to do? I never did javascript on grid... :(

        N 1 Reply Last reply
        0
        • T treuveni

          Mark Nischalke wrote:

          I would more than likely handle this on the client-side with some JavaScript.

          What you suggest to do? I never did javascript on grid... :(

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          treuveni wrote:

          What you suggest to do?

          learn JavaScript.


          I know the language. I've read a book. - _Madmatt

          T 1 Reply Last reply
          0
          • N Not Active

            treuveni wrote:

            What you suggest to do?

            learn JavaScript.


            I know the language. I've read a book. - _Madmatt

            T Offline
            T Offline
            treuveni
            wrote on last edited by
            #5

            Mark Nischalke wrote:

            learn JavaScript.

            10x, great answer

            1 Reply Last reply
            0
            • T treuveni

              Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:

              <asp:TemplateField HeaderText="החל מ-">
              <EditItemTemplate>
              <asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
              <FooterTemplate>
              <asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
              <ItemTemplate>
              <asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
              </asp:TemplateField>

              I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event - TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart"); but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?

              Steve EcholsS Offline
              Steve EcholsS Offline
              Steve Echols
              wrote on last edited by
              #6

              You might try doing this in RowDataBound event:

              if (e.Row.RowType == DataControlRowType.DataRow)
              {
              if (GridViewIpTab.EditIndex == e.Row.RowIndex)
              {
              TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.Row.RowIndex].FindControl("txtStart");
              // Do what you need to do
              }
              }

              In RowEditing do:

              GridViewIpTab.EditIndex = e.NewEditIndex;
              BindYourGrid();
              

              - S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.

              • S
                50 cups of coffee and you know it's on!
                Code, follow, or get out of the way.
              1 Reply Last reply
              0
              • T treuveni

                Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:

                <asp:TemplateField HeaderText="החל מ-">
                <EditItemTemplate>
                <asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
                <FooterTemplate>
                <asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
                <ItemTemplate>
                <asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
                </asp:TemplateField>

                I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event - TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart"); but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?

                M Offline
                M Offline
                MasttsaM
                wrote on last edited by
                #7

                You can reference this example: protected void gv4PPdata_RowDataBound(object sender, GridViewRowEventArgs e) { if((e.Row.RowState & DataControlRowState.Edit) > 0) { TextBox curText; for (int i = 1; i <= 6; i++) { curText = (TextBox)e.Row.Cells[i].Controls[0]; curText.Width = Unit.Pixel(60); if (i == 1) { curText.Enabled = false; } } } } Reference: http://www.programlive.tk

                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