How to make asp:Button ID unique in a DataGrid?

How to make asp:Button ID unique in a DataGrid?

am 30.10.2005 01:01:45 von Randall Parker

I have this element in an asp:DataGrid:



CommandName="EquipmentEdit"
CommandArgument='<%# DataBinder.Eval(Container,
"DataItem.owner_serial_num") %>'
Runat="server"
Text='<%# "Edit " + DataBinder.Eval(Container,
"DataItem.owner_serial_num") %>'
/>




I get this error when I try to view the page and I do not understand why the
expression I'm using to build the ID is not accepted:

Parser Error Message: '<%# "Edit" + DataBinder.Eval(Container,
"DataItem.owner_serial_num") %>' is not a valid identifier.

Source Error:

Line 21:
Line 22:
Line 23: Line 24: CommandName="EquipmentEdit"
Line 25: CommandArgument='<%# DataBinder.Eval(Container,
"DataItem.owner_serial_num") %>'

How to do this? I just want a button in a grid cell that the user can click on.


If I do not try to make the ID unique then I get a different error when I go to click
on a button in the grid:

Multiple controls with the same ID 'hyperlink1' were found. FindControl requires that
controls have unique IDs.

Re: How to make asp:Button ID unique in a DataGrid?

am 30.10.2005 01:06:08 von unknown

Post removed (X-No-Archive: yes)

Re: How to make asp:Button ID unique in a DataGrid?

am 30.10.2005 01:36:24 von Randall Parker

Stan,

I do not understand your suggestion. Bind what in CodeBehind?

How can I make each ID on each button on row different?

Usenet Honey Pot wrote:
> Randall Parker
> wrote in news:e3go9yN3FHA.3000@TK2MSFTNGP12.phx.gbl:
>
>
>>I get this error when I try to view the page and I do not understand
>>why the expression I'm using to build the ID is not accepted:
>>
>> Parser Error Message: '<%# "Edit" + DataBinder.Eval(Container,
>>"DataItem.owner_serial_num") %>' is not a valid identifier.
>>
>
>
> I would bind it in code behind - it'll be eaiser to maintain too : )
>

Re: How to make asp:Button ID unique in a DataGrid?

am 30.10.2005 02:36:17 von patrickige

Randall try looking at this artcile at
http://www.datawebcontrols.com/faqs/ProgrammaticAccess/Acces singTemplateColu
mnContents.shtml
that should help
Patrick


"Randall Parker"
wrote in message news:OZkpTGO3FHA.3400@tk2msftngp13.phx.gbl...
> Stan,
>
> I do not understand your suggestion. Bind what in CodeBehind?
>
> How can I make each ID on each button on row different?
>
> Usenet Honey Pot wrote:
> > Randall Parker
> > wrote in news:e3go9yN3FHA.3000@TK2MSFTNGP12.phx.gbl:
> >
> >
> >>I get this error when I try to view the page and I do not understand
> >>why the expression I'm using to build the ID is not accepted:
> >>
> >> Parser Error Message: '<%# "Edit" + DataBinder.Eval(Container,
> >>"DataItem.owner_serial_num") %>' is not a valid identifier.
> >>
> >
> >
> > I would bind it in code behind - it'll be eaiser to maintain too : )
> >

Re: How to make asp:Button ID unique in a DataGrid?

am 30.10.2005 20:49:28 von Gaurav Vaish

: Parser Error Message: '<%# "Edit" + DataBinder.Eval(Container,
: "DataItem.owner_serial_num") %>' is not a valid identifier.


Don't attempt to provide an ID yourself.

Or if at all.. give a simple plain ID.

To get the item back, work the DataGridItem - which is derived from
TableRow. Each item represents full row.
Then you can do something like (say, in ItemCommand event handler):

TableCell cell = e.Item.Cells[index];
Button b = (Button) cell.FindControl("ID-that-you-gave");


HTH


--
Cheers,
Gaurav Vaish
http://mastergaurav.org
-----------------------------