Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference text of DataGridLinkButton 1

Status
Not open for further replies.

JGresko

Programmer
Apr 24, 2002
86
US
Hi,

I have a DataGrid that contains a LinkButton in the first column. When the link is clicked on, it's supposed to pass it's name to another DataGrid to show it's part of a subgroup. I've been unable to figure out how to reference the text of the link to add it to the new Grid.

I'm creating the cell like this:

Code:
<asp:ButtonColumn HeaderText=&quot;Column&quot; CommandName=&quot;SortMe&quot; ButtonType=&quot;LinkButton&quot; DataTextField=&quot;Column&quot;></asp:ButtonColumn>

In the associated dgColumns_ItemCommand action I've caught the
Code:
CommandName=&quot;SortMe&quot;
to add a column to the second Grid, but can't get the name of which LinkButton sent the request. I've tried...

Code:
Trace.Write(e.Item.Cells(0).Text)
which gives me nothing

Code:
e.Item.Cells(0).ToString
gives me system.Web.UI.WebControls.TableCell

Code:
e.Item.Cells(0).Controls.Item(0).ToString
gives me System.Web.UI.WebControls.DataGridLinkButton


Can someone tell me the correct method of accessing the name of the link?

Thanks,

Judy

 

One more thing... I'm creating each LinkButton in another action like this:

Code:
Sub lbOutput_ItemClicked(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebListbar.WebListbarItemEvent) Handles lbOutput.ItemClicked
        Dim scRow As DataRow
        scRow = ColsGrid.NewRow()
        scRow(&quot;Column&quot;) = e.Item.Text
        ColsGrid.Rows.Add(scRow)
        CreateSQL.ColsView = New DataView(ColsGrid)
        BindGrid(dgColumns, CreateSQL.ColsView)
End Sub

Is there a way to add something here to differentiate the links later?

 

I figured it out...

I converted the ButtonColumn to a TemplateColumn and set the CommandName to be the same as the text.

Code:
<asp:TemplateColumn HeaderText=&quot;Column&quot;>
 <ITEMTEMPLATE>
  <asp:LinkButton runat=&quot;server&quot; Text='<%# DataBinder.Eval(Container, &quot;DataItem.Column&quot;) %>' CommandName='<%# DataBinder.Eval(Container, &quot;DataItem.Column&quot;) %>' CausesValidation=&quot;false&quot;></asp:LinkButton>
 </ItemTemplate>
</asp:TemplateColumn>
 
Thanks Mark... I was begining to look like I was 'talkin to myself', but hey isn't that what all programmers do :)

...I may have spoken too soon however because that solution didn't solve the whole problem... I still need to access the text to make the &quot;Delete&quot; command work. phooey :-(
 
Yea most of us do talk to ourselves cause no one else understands us.

Unfortunately I don't know that I can help you.

I do know that I used a command to find certain labels in a datalist once. Let me see where'd that go..........
..... There it is.
myLabel = DataList1.Items(I).FindControl(&quot;lblTax2&quot;)

If myLabel.Text = &quot;$0.00&quot; Then
myLabel.Visible = False
End If

don't know if that can help you but your welcome to it. That'l do donkey, that'l do
[bravo] Mark
 
By switching tactics I've finally found a work around ---

If I can't access the LinkButton in the DataGrid, it turns out I can access that col,row in the DataGridView and there I can get the needed text (solution below)


Code:
Dim index As Integer = e.Item.ItemIndex
Dim nField As String = CreateSQL.ColsView.Item(index).Item(0)



ugh! [pc] No problem this elementary should have required over a full day to solve...


...ok, I'm back to work now [pc2] hopefully to make better progress at finishing this app!


Cheers
 
lmao
No problem this elementary should have required over a full day to solve

IMO it seems that it is always the simple problems that take the longest time to solve. Often because you don't seem to be making any progress till suddenly boom it works. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top