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. Problem with GridView: How to change the text of Button in a GridView Cell ?

Problem with GridView: How to change the text of Button in a GridView Cell ?

Scheduled Pinned Locked Moved ASP.NET
csharphelpquestionasp-nettutorial
8 Posts 2 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.
  • P Offline
    P Offline
    Purish Dwivedi
    wrote on last edited by
    #1

    How can I show additional button in a gridview cell based on another cell value.I am using asp.net and c#. I have ON or OFF values in a GridView cell. Based on this value I want to show a button (opposite Toggle (OFF/On) correspondingly) in another cell. This is my code. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.Cells[2].Text== "0") e.Row.Cells[2].Text = "OFF"; else e.Row.Cells[2].Text = "ON"; } please help. Thank You

    A 1 Reply Last reply
    0
    • P Purish Dwivedi

      How can I show additional button in a gridview cell based on another cell value.I am using asp.net and c#. I have ON or OFF values in a GridView cell. Based on this value I want to show a button (opposite Toggle (OFF/On) correspondingly) in another cell. This is my code. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.Cells[2].Text== "0") e.Row.Cells[2].Text = "OFF"; else e.Row.Cells[2].Text = "ON"; } please help. Thank You

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Are you looking for UnBound TemplateField ? Simply add

           " CommandName="ToggleClick"
      

      CommandArgument='<%#Eval("Toggle") %>/>

      and use OnRowCommand to handle this event. :)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Microsoft Bing MAP using Javascript
      CLR objects in SQL Server 2005
      Uncommon C# Keywords
      /xml>

      P 1 Reply Last reply
      0
      • A Abhishek Sur

        Are you looking for UnBound TemplateField ? Simply add

             " CommandName="ToggleClick"
        

        CommandArgument='<%#Eval("Toggle") %>/>

        and use OnRowCommand to handle this event. :)

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Microsoft Bing MAP using Javascript
        CLR objects in SQL Server 2005
        Uncommon C# Keywords
        /xml>

        P Offline
        P Offline
        Purish Dwivedi
        wrote on last edited by
        #3

        thanks for the reply, but there is something wrong with this code. Can u recheck it plz? Thank You

        A 1 Reply Last reply
        0
        • P Purish Dwivedi

          thanks for the reply, but there is something wrong with this code. Can u recheck it plz? Thank You

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          Yes.. Actually I have written this directly.. Not tried out.... Can you let me know what error you are getting ... ? Well, Eval("field") should be changed with your valid database field ?? Also change the fieldnames according to the datasource you bound to.

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Microsoft Bing MAP using Javascript
          CLR objects in SQL Server 2005
          Uncommon C# Keywords
          /xml>

          P 1 Reply Last reply
          0
          • A Abhishek Sur

            Yes.. Actually I have written this directly.. Not tried out.... Can you let me know what error you are getting ... ? Well, Eval("field") should be changed with your valid database field ?? Also change the fieldnames according to the datasource you bound to.

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Microsoft Bing MAP using Javascript
            CLR objects in SQL Server 2005
            Uncommon C# Keywords
            /xml>

            P Offline
            P Offline
            Purish Dwivedi
            wrote on last edited by
            #5

            Actually I am using it as a TemplateField. It's value is not coming from database. what can be the solution? Thank You.

            A 1 Reply Last reply
            0
            • P Purish Dwivedi

              Actually I am using it as a TemplateField. It's value is not coming from database. what can be the solution? Thank You.

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #6

              Then Just place True / false instead of Eval statement.. :)

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Microsoft Bing MAP using Javascript
              CLR objects in SQL Server 2005
              Uncommon C# Keywords
              /xml>

              P 1 Reply Last reply
              0
              • A Abhishek Sur

                Then Just place True / false instead of Eval statement.. :)

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Microsoft Bing MAP using Javascript
                CLR objects in SQL Server 2005
                Uncommon C# Keywords
                /xml>

                P Offline
                P Offline
                Purish Dwivedi
                wrote on last edited by
                #7

                I have written this. theres is some problem. It shows "Convert.ToBoolean(true)". What is the problem? <asp:TemplateField HeaderText="Mode"> <ItemTemplate> <asp:Button runat="server" Text="<%!Convert.ToBoolean(true) %>" CommandName="ToggleClick" CommandArgument=<%#true %>/> </ItemTemplate> </asp:TemplateField> Thank You

                A 1 Reply Last reply
                0
                • P Purish Dwivedi

                  I have written this. theres is some problem. It shows "Convert.ToBoolean(true)". What is the problem? <asp:TemplateField HeaderText="Mode"> <ItemTemplate> <asp:Button runat="server" Text="<%!Convert.ToBoolean(true) %>" CommandName="ToggleClick" CommandArgument=<%#true %>/> </ItemTemplate> </asp:TemplateField> Thank You

                  A Offline
                  A Offline
                  Abhishek Sur
                  wrote on last edited by
                  #8

                  No no.. write this...

                  <asp:TemplateField HeaderText="Mode">
                  <ItemTemplate>
                  <asp:Button runat="server" Text="True" CommandName="ToggleClick" CommandArgument="True" />
                  </ItemTemplate>
                  </asp:TemplateField>

                  In CommandArgument you need to specify what you want to pass to the event generated when button is clicked. I have placed true there, which is not required. Replace appropriate element there (I mean the field which might be dependent on the button) :)

                  Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                  My Latest Articles-->** Microsoft Bing MAP using Javascript
                  CLR objects in SQL Server 2005
                  Uncommon C# Keywords
                  /xml>

                  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