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

ASP.NET

 
AnswerRe: Session End problem Pin
J4amieC26-Apr-06 2:18
J4amieC26-Apr-06 2:18 
Questionarray Pin
ptvce26-Apr-06 1:23
ptvce26-Apr-06 1:23 
AnswerRe: array Pin
Rob Philpott26-Apr-06 6:00
Rob Philpott26-Apr-06 6:00 
QuestionHide column in gridview filled by dataset Pin
dumser126-Apr-06 1:06
dumser126-Apr-06 1:06 
AnswerRe: Hide column in gridview filled by dataset Pin
minhpc_bk26-Apr-06 16:20
minhpc_bk26-Apr-06 16:20 
QuestionBinding DataGrid Control in user friendly way? Pin
k_bhawna26-Apr-06 1:03
k_bhawna26-Apr-06 1:03 
AnswerRe: Binding DataGrid Control in user friendly way? Pin
sathish s26-Apr-06 1:52
sathish s26-Apr-06 1:52 
Questionmy datagrid`s template column's textbox and label are coming in a single column Pin
MissionSuccess26-Apr-06 0:56
MissionSuccess26-Apr-06 0:56 
hai
i am ajay
i am making a datagrid at runtime and adding a template column to it.in the template column i am using a textbox and the second column is a label.
everything is working fine for me.but in the datagrid the two columns(textbox and label) are coming in a single column.although i have set all the necessary properties of datagrid at run time.

plz resolve my problem.
i am giving my code snippet.

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 temp1 As String
Dim temp2 As String
temp1 = TextBox1.Text
temp2 = TextBox2.Text
Dim tempcol As New TemplateColumn
'tempcol.HeaderText = temp1

'Header Template
tempcol.HeaderTemplate = New MyTemp(ListItemType.Header, temp1, temp2)

'Item Template
tempcol.ItemTemplate = New MyTemp(ListItemType.Item, temp1, temp2)

'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 panel
Me.Panel1.Controls.Add(DataGrid1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Template()
End Sub
End Class
Public Class MyTemp
Implements ITemplate
Dim TemplateType As ListItemType
Dim Field1 As String
Dim Field2 As String
Dim heading1 As String
Dim heading2 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 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


AnswerRe: my datagrid`s template column's textbox and label are coming in a single column Pin
minhpc_bk26-Apr-06 16:10
minhpc_bk26-Apr-06 16:10 
QuestionSome problem regarding site. Pin
Chetan Ranpariya26-Apr-06 0:39
Chetan Ranpariya26-Apr-06 0:39 
AnswerRe: Some problem regarding site. Pin
enjoycrack26-Apr-06 0:52
enjoycrack26-Apr-06 0:52 
GeneralRe: Some problem regarding site. Pin
Chetan Ranpariya26-Apr-06 18:25
Chetan Ranpariya26-Apr-06 18:25 
GeneralRe: Some problem regarding site. Pin
VaibhavJ26-Apr-06 19:06
VaibhavJ26-Apr-06 19:06 
GeneralRe: Some problem regarding site. Pin
Chetan Ranpariya26-Apr-06 19:18
Chetan Ranpariya26-Apr-06 19:18 
GeneralRe: Some problem regarding site. Pin
enjoycrack26-Apr-06 20:12
enjoycrack26-Apr-06 20:12 
AnswerRe: Some problem regarding site. Pin
dansoft26-Apr-06 3:53
dansoft26-Apr-06 3:53 
QuestionDatagrid Footer Pin
kuwl_mark26-Apr-06 0:28
kuwl_mark26-Apr-06 0:28 
AnswerRe: Datagrid Footer Pin
Mike Ellison26-Apr-06 2:41
Mike Ellison26-Apr-06 2:41 
QuestionFirst Selected Button Pin
sroberts8226-Apr-06 0:27
sroberts8226-Apr-06 0:27 
AnswerRe: First Selected Button Pin
enjoycrack26-Apr-06 0:56
enjoycrack26-Apr-06 0:56 
GeneralRe: First Selected Button Pin
sroberts8226-Apr-06 1:00
sroberts8226-Apr-06 1:00 
QuestionOnly one top level element is allowed in an XML document. Error processing resource Pin
sasire1826-Apr-06 0:08
sasire1826-Apr-06 0:08 
QuestionCan .net passport be used locally? Pin
KaKa'25-Apr-06 23:48
KaKa'25-Apr-06 23:48 
Questionhow to display pictures,text and tables in textarea control? Pin
nnnsreenu25-Apr-06 23:10
nnnsreenu25-Apr-06 23:10 
AnswerRe: how to display pictures,text and tables in textarea control? Pin
enjoycrack25-Apr-06 23:16
enjoycrack25-Apr-06 23:16 

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.