Getting text from linkButtons???
-
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.
-
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.
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 -
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.
-
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, ParsiphalThanks, 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.
-
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..
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>
-
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.
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:
-
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:
Thanks, it works!!!