|
 |
aspx_professional thread: Re: Help on linkbutton.Text
Message #1 by anguyen@f... on Fri, 1 Mar 2002 17:43:26
|
|
I found a solution as you can find the selected row, cast the control to
type of Linkbutton and show it's Text property. and here is the code.
protected void Show_Name( System.Object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs e ) {
int row = Convert.ToInt32(e.Item.ItemIndex);
// in this case i click the linkbutton in the first column.
Response.Write ("<BR>1. --->at column# " + col + " i click " +
((LinkButton)dg.Items[row].Cells[ 0 ].Controls[ 0 ]).Text);
}
hmm! could i kow which cell (column) i click???
Thanks
>
> How can i know the value LinkButton.Text.
>
> I have two linkbutton in a datagrid as below.
> when the Show_Name executeed i Get the error
> "System.NullReferenceException: Object reference not set to an instance
of
> an object."
>
> is this due to the cast condition or the somthingelse ???
>
> Thank in advance for any help. The partial code below.
>
>
>
> protected void Show_Name( System.Object sender,
> System.Web.UI.WebControls.DataGridCommandEventArgs e ) {
>
>
> LinkButton myButton = (LinkButton)(e.Item.FindControl("LinkA"));
>
> if (myButton.Text == "LinkA"){ //**** error occur here
> Response.Write ("<BR>---->" + myButton.Text);}
> else {
> Response.Write ("<BR>---->" + myButton.Text);};
> }
>
>
> <asp:DataGrid id="dg"
> onItemCommand="Show_Name"
>
> <column>
> <asp:ButtonColumn Text="LinkA" CommandName="GotoA"
> ButtonType="LinkButton"/>
>
> <asp:ButtonColumn Text="LinkB" CommandName="GOTOB"
> ButtonType="LinkButton"/>
> </columns>
>
> </asp:DataGrid>
|
|
 |