Dynamically created control in Datagrid problem

E

Elton Wang

Hi Wanky,

Following is solution. I'm sure it works.

' Add both textbox and checkbox in datagrid
<asp:TemplateColumn HeaderText="Choice">
<ItemTemplate>
<asp:CheckBox ID="ckChoice"
Runat="server"></asp:CheckBox>
<asp:TextBox ID="txtChoice"
Runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>


' in ItemDataBound set one of control invisible according
to type

Dim drv As DataRowView = e.Item.DataItem

If drv(FieldTypeIndex).ToString.Equals("Textbox") Then
e.Item.FindControl("ckChoice").Visible = False
Else
e.Item.FindControl("txtChoice").Visible = False
End If


' in save button Click retrieve control type depending on
type filed

For Each item As DataGridItem In Me.dgdSearch.Items
If item.Cells(FieldTypeIndex).Text.Equals("Textbox")
Then
Dim txtCtrl As TextBox = CType(item.FindControl
("txtChoice"), TextBox)
' process
Else
Dim ck As CheckBox = CType(item.FindControl
("ckChoice"), CheckBox)
' process
End If
Next

If you still have problem, please let me know.

HTH

Elton Wang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top