Use the RADIO button to select the DataGrid line

xiaoxiao2021-03-06  120

[Date: 2004-10-7] Source: http: //www.cnblogs.com/xenogear/ Author: do not know anything [font: medium and small]

(Read from http://www.dotnetBips.com/displayArticle.aspx?id=147 Source Code Download) This problem occurs because the Radiobuttons control cannot be added directly in the DataGrid template column. Because DataGrid will generate a unique name to each radio button so that these radio buttons are not a group.

The solution to the problem is to add a Label control in the template column. Write elements in the DataGrid ItemDatabase, such as:

IF

E.Item.itemType

=

ListItemType.alternatingItem

Oral

E.Item.itemType

=

ListItemType.Item

THEN

DIM

r

AS

Label R

=

E.Item.FindControl

"

Label2

"

R.Text

=

"

"

&

E.Item.cells

1

) .Text

&

"

> "

End

IF

If you want to get the selected value, you have to use Request.Form to get it.

Label3.Text

=

REQUEST.FORM

"

MyRadiogroup

"

)

If you want to keep the status after postback, you have to do it yourself.

DIM

i

AS

DataGridItem

For

Each

i

In

DataGrid1.Items

IF

ItemType

=

ListItemType.alternatingItem

Oral

ItemType

=

ListItemType.Item

THEN

DIM

r

AS

Label R

=

I.FindControl

"

Label2

"

)

IF

R.Text.indexof (label3.text)

>

0

THEN

R.Text

=

"

"

&

I.cells

1

) .Text

&

"

Checked> "

Else

R.Text

=

"

"

&

I.cells

1

) .Text

&

"

> "

End

IF

End

IF

NEXT