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. Getting text from linkButtons???

Getting text from linkButtons???

Scheduled Pinned Locked Moved ASP.NET
dockerhelpquestion
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.
  • R Offline
    R Offline
    Reinier van de Wetering
    wrote on last edited by
    #1

    I've got a column with linkbuttons in a datagrid, a retrieve the text for the buttons using DataBind.Eval(). When a button is clicked the onclick event fires and then i need the button's text. When i tried it without the DataBind.Eval() function and just typed in any value for the button it works fine. Can anyone help me? <%#DataBinder.Eval(Container.DataItem, "JobNo")%> Thank you, Reinier.

    P T N 3 Replies Last reply
    0
    • R Reinier van de Wetering

      I've got a column with linkbuttons in a datagrid, a retrieve the text for the buttons using DataBind.Eval(). When a button is clicked the onclick event fires and then i need the button's text. When i tried it without the DataBind.Eval() function and just typed in any value for the button it works fine. Can anyone help me? <%#DataBinder.Eval(Container.DataItem, "JobNo")%> Thank you, Reinier.

      P Offline
      P Offline
      parsiphal
      wrote on last edited by
      #2

      Hi there, the purpose of such a column is to give some functionality to apply to each row. The idea, as far as I see, is that the same text appears in all button, for they are just command, like 'edit', 'see detail', 'cancel', 'buy'... Guessing from your code snippet, I think your user should perhaps apply for one job by its internal code, or perhaps simply go to detail on that job. Well, if you need your JobID for such an operation, it's better to put it on a BoundColumn. You still use your button column, with a fixed text like 'Apply' in all rows. When use click the button, the you can access ItemData, wich is a Row of the grid, and contains also the JobID value corresponding to the button pressed. I strongly encurage you to keep separate elements who are going just for UserInterface (the text button) from those are functional to your application (the value you want to 'play'). Perhaps, even the separation you obtain from the scenario i point out should be strongened, taking the value not from the Grid, instead from the (underlaying) DataSet. Playing with buttons' text is funny, I know myself, for you feel very sharp and you have a bit of laugh in it... but it can turn against your sanity just beyond tomorrow, as I've experienced myself. I hope not boaring you, Parsiphal

      R 1 Reply Last reply
      0
      • R Reinier van de Wetering

        I've got a column with linkbuttons in a datagrid, a retrieve the text for the buttons using DataBind.Eval(). When a button is clicked the onclick event fires and then i need the button's text. When i tried it without the DataBind.Eval() function and just typed in any value for the button it works fine. Can anyone help me? <%#DataBinder.Eval(Container.DataItem, "JobNo")%> Thank you, Reinier.

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

        I don't know what your OnClick event does (since you don wrote it) but you might put the <%#DataBinder.Eval(Container.DataItem, "JobNo")%> inside the OnClick event allso..

        R 1 Reply Last reply
        0
        • P parsiphal

          Hi there, the purpose of such a column is to give some functionality to apply to each row. The idea, as far as I see, is that the same text appears in all button, for they are just command, like 'edit', 'see detail', 'cancel', 'buy'... Guessing from your code snippet, I think your user should perhaps apply for one job by its internal code, or perhaps simply go to detail on that job. Well, if you need your JobID for such an operation, it's better to put it on a BoundColumn. You still use your button column, with a fixed text like 'Apply' in all rows. When use click the button, the you can access ItemData, wich is a Row of the grid, and contains also the JobID value corresponding to the button pressed. I strongly encurage you to keep separate elements who are going just for UserInterface (the text button) from those are functional to your application (the value you want to 'play'). Perhaps, even the separation you obtain from the scenario i point out should be strongened, taking the value not from the Grid, instead from the (underlaying) DataSet. Playing with buttons' text is funny, I know myself, for you feel very sharp and you have a bit of laugh in it... but it can turn against your sanity just beyond tomorrow, as I've experienced myself. I hope not boaring you, Parsiphal

          R Offline
          R Offline
          Reinier van de Wetering
          wrote on last edited by
          #4

          Thanks, i'll try something else. I just started with asp.net, or for that fact with any web applications, so i'll need to learn all the ways to access and use data, this was just the first thing that i thought might work. I'll probably struggle with simple stuff like this for another couple of months (or years!!). Thanks for the advise. Reinier.

          1 Reply Last reply
          0
          • T thomasa

            I don't know what your OnClick event does (since you don wrote it) but you might put the <%#DataBinder.Eval(Container.DataItem, "JobNo")%> inside the OnClick event allso..

            R Offline
            R Offline
            Reinier van de Wetering
            wrote on last edited by
            #5

            I tried to send more code, but it does'nt look like it saved it, it only send that one line. Hope it works now. protected void (object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; lblJobNo = lb.Text; } <\Script> <ItemTemplate> <asp:LinkButton ID="lbJobNo" runat="server" OnClick="OnClick"> <%#DataBinder.Eval(Container.DataItem, "JobNo")%> </asp:LinkButton> </ItemTemplate> </x-turndown>

            1 Reply Last reply
            0
            • R Reinier van de Wetering

              I've got a column with linkbuttons in a datagrid, a retrieve the text for the buttons using DataBind.Eval(). When a button is clicked the onclick event fires and then i need the button's text. When i tried it without the DataBind.Eval() function and just typed in any value for the button it works fine. Can anyone help me? <%#DataBinder.Eval(Container.DataItem, "JobNo")%> Thank you, Reinier.

              N Offline
              N Offline
              Noman Nadeem
              wrote on last edited by
              #6

              Hi reinier, by linkButton i'm assuming you mean you created a template column and added an ... your item should look something like the following: <%# DataBinder.Eval(Container.DataItem,"JobNo") %> you need to handle the ItemCommand event of your datagrid( myGrid ) this.myGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.myGrid_ItemCommand); your myGrid_ItemCommand should look something like the following: private void myGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if ( e.CommandName == "myJobNo" && e.CommandArgument.ToString() != "") { // this contains the JobNo field you want !! string strJobNo = e.CommandArgument.ToString(); // do processing here } } Hope this helps regards, Noman Nadeem :zzz:

              R 1 Reply Last reply
              0
              • N Noman Nadeem

                Hi reinier, by linkButton i'm assuming you mean you created a template column and added an ... your item should look something like the following: <%# DataBinder.Eval(Container.DataItem,"JobNo") %> you need to handle the ItemCommand event of your datagrid( myGrid ) this.myGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.myGrid_ItemCommand); your myGrid_ItemCommand should look something like the following: private void myGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if ( e.CommandName == "myJobNo" && e.CommandArgument.ToString() != "") { // this contains the JobNo field you want !! string strJobNo = e.CommandArgument.ToString(); // do processing here } } Hope this helps regards, Noman Nadeem :zzz:

                R Offline
                R Offline
                Reinier van de Wetering
                wrote on last edited by
                #7

                Thanks, it works!!!

                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