Click here to Skip to main content
15,918,742 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: validate a file before upload Pin
NeverHeardOfMe25-Apr-06 22:25
NeverHeardOfMe25-Apr-06 22:25 
AnswerRe: validate a file before upload Pin
enjoycrack25-Apr-06 22:53
enjoycrack25-Apr-06 22:53 
GeneralRe: validate a file before upload Pin
fmardani25-Apr-06 23:16
fmardani25-Apr-06 23:16 
Questionto print or save datagrid control in asp.net 1.1 Pin
rajinder s25-Apr-06 21:33
rajinder s25-Apr-06 21:33 
AnswerRe: to print or save datagrid control in asp.net 1.1 Pin
Praveen_S26-Apr-06 1:51
Praveen_S26-Apr-06 1:51 
QuestionComponentArt give me componentart_webui_client/2006_1_1208/A573G988.js not found Pin
sasire1825-Apr-06 21:31
sasire1825-Apr-06 21:31 
AnswerRe: ComponentArt give me componentart_webui_client/2006_1_1208/A573G988.js not found Pin
minhpc_bk26-Apr-06 0:05
minhpc_bk26-Apr-06 0:05 
QuestionControl '_ctl0__ctl2_lbl1' of type 'TextBox' must be placed inside a form tag with runat=server. Pin
MissionSuccess25-Apr-06 21:30
MissionSuccess25-Apr-06 21:30 
hai everyone
i m ajay.
i m facing a problem related to creating a textbox in template column of a datagrid at runtime.i am giving my code snippet.although when i m taking a label instead of textbox it works fine.but when i m dealing with a textbox it gives me the error

"Control '_ctl0__ctl2_lbl1' of type 'TextBox' must be placed inside a form tag with runat=server."

my coding is------



Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Template()
End Sub


Private Sub Template()

Dim DataGrid1 As New DataGrid

DataGrid1.AutoGenerateColumns = False
DataGrid1.GridLines = GridLines.Both
DataGrid1.BackColor = Color.Pink
DataGrid1.BorderWidth = Unit.Pixel(2)
DataGrid1.BorderColor = Color.Blue
DataGrid1.HeaderStyle.BackColor = Color.Yellow
DataGrid1.HeaderStyle.ForeColor = Color.Brown
DataGrid1.HeaderStyle.Font.Bold = True
DataGrid1.CellPadding = 10

Dim Field1 As String

Dim Field2 As String

Dim Header1 As String

Dim Header2 As String

Field1 = "name"

Field2 = "description"

Header1 = "Name"

Header2 = "Description"
Dim tempcol As New TemplateColumn
'Dim tbc As New MyTemp(ListItemType.Item, Field1, Field2)
'tempcol.ItemTemplate = tbc


' Header Template

tempcol.HeaderTemplate = New MyTemp(ListItemType.Header, Header1, Header2)

' Item Template

tempcol.ItemTemplate = New MyTemp(ListItemType.Item, Field1, Field2)

' Add Template into Grid

DataGrid1.Columns.Add(tempcol)

' Binding Data Source
Dim cnn As New SqlConnection("")
Dim da As New SqlDataAdapter("")
Dim ds As New DataSet
da.Fill()
DataGrid1.DataSource = ds
DataGrid1.DataMember = ""
DataGrid1.DataBind()

' Bind Grid into Label

' Me.lblShowGrid.Controls.Add(DataGrid1)
Page.Controls.Add(DataGrid1)

End Sub
End Class


Public Class MyTemp

Implements ITemplate

Dim TemplateType As ListItemType

Dim Field1 As String

Dim Field2 As String



Sub New(ByVal type As ListItemType, ByVal fld1 As String, ByVal fld2 As String)

TemplateType = type

Field1 = fld1

Field2 = fld2

End Sub

Sub InstantiateIn(ByVal Container As Control) Implements ITemplate.InstantiateIn

'Dim lbl1 As New WebControls.TextBox
Dim lbl1 As New TextBox
lbl1.BackColor = Color.Beige
Dim lbl2 As Label = New Label

Dim lc1 As LiteralControl = New LiteralControl

Dim lc2 As LiteralControl = New LiteralControl

Select Case TemplateType

Case ListItemType.Header

lc1.ID = "textbox1"

lc1.Text = Field1


Container.Controls.Add(lc1)

lc2.ID = "lc2"

lc2.Text = Field2

Container.Controls.Add(lc2)

Case ListItemType.Item

lbl1.ID = "lbl1"

AddHandler lbl1.DataBinding, AddressOf BindIntegerColumn

Container.Controls.Add(lbl1)

lbl2.ID = "lbl2"

AddHandler lbl2.DataBinding, AddressOf BindStringColumn

Container.Controls.Add(lbl2)

End Select

End Sub

Sub BindIntegerColumn(ByVal Sender As Object, ByVal e As EventArgs)
Dim lbl1 As New TextBox
lbl1 = CType(Sender, TextBox)
Dim Container As DataGridItem = CType(lbl1.NamingContainer, DataGridItem)
lbl1.Text = DataBinder.Eval(Container.DataItem, Field1)

End Sub

Sub BindStringColumn(ByVal sender As Object, ByVal e As EventArgs)

Dim lbl2 As Label = CType(sender, Label)

Dim Container As DataGridItem = CType(lbl2.NamingContainer, DataGridItem)

lbl2.Text = DataBinder.Eval(Container.DataItem, Field2)
End Sub
End Class



thanx in advance
any suggetion will be highly appriciated
ajay

AnswerRe: Control '_ctl0__ctl2_lbl1' of type 'TextBox' must be placed inside a form tag with runat=server. Pin
minhpc_bk25-Apr-06 22:44
minhpc_bk25-Apr-06 22:44 
QuestionGoogle Web Service returned and open a new page? Pin
nets070625-Apr-06 20:48
nets070625-Apr-06 20:48 
AnswerRe: Google Web Service returned and open a new page? Pin
minhpc_bk26-Apr-06 0:01
minhpc_bk26-Apr-06 0:01 
QuestionRe: Google Web Service returned and open a new page? Pin
TheEagle28-Jun-06 17:49
TheEagle28-Jun-06 17:49 
Questiondifference between configSource and file attributes in web.config Pin
chakkara200325-Apr-06 19:34
chakkara200325-Apr-06 19:34 
AnswerRe: difference between configSource and file attributes in web.config Pin
minhpc_bk25-Apr-06 23:58
minhpc_bk25-Apr-06 23:58 
GeneralRe: difference between configSource and file attributes in web.config Pin
chakkara200326-Apr-06 3:08
chakkara200326-Apr-06 3:08 
QuestionASP.net Ajax Pin
NICE TO MEET25-Apr-06 17:30
NICE TO MEET25-Apr-06 17:30 
AnswerRe: ASP.net Ajax Pin
CWIZO25-Apr-06 21:44
CWIZO25-Apr-06 21:44 
Questiondebug vs 2003 javascript Pin
raquidd2225-Apr-06 17:27
raquidd2225-Apr-06 17:27 
AnswerRe: debug vs 2003 javascript Pin
minhpc_bk25-Apr-06 22:58
minhpc_bk25-Apr-06 22:58 
Questioncommand window vs 2003 Pin
raquidd2225-Apr-06 17:23
raquidd2225-Apr-06 17:23 
AnswerRe: command window vs 2003 Pin
Guffa25-Apr-06 20:20
Guffa25-Apr-06 20:20 
QuestionRedirect back to original page causing problem Pin
OzSoft Solutions25-Apr-06 16:07
OzSoft Solutions25-Apr-06 16:07 
AnswerRe: Redirect back to original page causing problem Pin
Guffa25-Apr-06 20:32
Guffa25-Apr-06 20:32 
GeneralRe: Redirect back to original page causing problem Pin
OzSoft Solutions25-Apr-06 20:39
OzSoft Solutions25-Apr-06 20:39 
QuestionLogin Control, custom authentication Pin
2hdass25-Apr-06 16:00
2hdass25-Apr-06 16:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.