GridView template field events - asp.net

I have added Checkbox and Radio buttons as column values to the GridView in runtime.
Now, i am unable to fire Checkbox_CheckedChanged event upon Checkbox.checked
Any suggestions on how to call event ? Below is the Grid i implemented.
Below is the source code:
1) Grid Init
Dim COUNT As Integer = 0
For i As Integer = 0 To ListHeaderDataFieldArray.Count - 1
If ListHeaderDataFieldArray(i) = Me.CRMSignCond Then
Dim TemplateCol As New TemplateField
TemplateCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center
TemplateCol.ItemStyle.Width = New Unit(RowChildWidth)
TemplateCol.HeaderText = ListHeaderTextArray(i)
TemplateCol.ItemTemplate = New GridViewTemplate(DataControlRowType.DataRow, ListHeaderDataFieldArray(i))
GridviewChild.Columns.Add(TemplateCol)
Else
If ListHeaderTextArray(i) = "Target Sign" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
ElseIf ListHeaderTextArray(i) = "Consolidate" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
ElseIf ListHeaderTextArray(i) = "Signing Group" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
Else
Dim colItem As BoundField = New BoundField
colItem.HeaderText = ListHeaderTextArray(i)
colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
End If
End If
2) Adding Controls to the GridView Columns in "RowDataBound" event.
Protected Sub GridviewChild_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridviewChild.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow AndAlso Not String.IsNullOrEmpty(CRMSignCond) Then
Dim s As String = ""
Dim lbValue As Label = DirectCast(e.Row.Cells(5).FindControl("lbValue"), Label)
e.Row.Cells(5).Attributes.Add("onmousemove", "Show('" + lbValue.Text + "')")
e.Row.Cells(5).Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();")
End If
Dim cbTargetSign As New CheckBox
Dim rbConsolidate As New RadioButton
Dim tbSignGrp As New TextBox
cbTargetSign.ID = "chkSelect"
cbTargetSign.AutoPostBack = True
rbConsolidate.ID = "rbConsolidate"
tbSignGrp.ID = "tbConsolidate"
tbSignGrp.Width = 25
If Not e.Row.RowIndex = -1 Then
e.Row.Cells(6).Controls.Add(cbTargetSign)
e.Row.Cells(4).Controls.Add(tbSignGrp)
For i As Integer = 0 To 1
rbConsolidate = New RadioButton()
If i = 0 Then
rbConsolidate.Text = "YES"
Else
rbConsolidate.Text = "NO"
End If
'ii.Location = New Point(20, tt)
'ii.Tag = fileArray(i)
'tt = tt + 20
rbConsolidate.GroupName = "Consolidate"
e.Row.Cells(7).Controls.Add(rbConsolidate)
Next
End If
End Sub
Regards,
VK

You are adding and binding events programmatically in code behind and adding them to the GridView. And since dynamic Controls need to be recreated on every time the page is loaded to function properly, you should make sure the RowDataBound event is triggered on every Page Load, and that includes a PostBack.
So I'm guessing you do this (like you would normally):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
GridView1.DataSource = mySource
GridView1.DataBind
End If
End Sub
Change it to
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
GridView1.DataSource = mySource
GridView1.DataBind
End Sub

Related

Allow only some check boxes to be checked. Loaded on page_load

I am dynamically adding asp check boxes to my page based off of number of rows in my db table, by ID. Also the checkbox is being assigned an ID from the db table. I also two columns in my db table "numberOffered" and "numberAllowed". My idea is on page load only allow the user to check say 3 of the 10 check boxes shown. I have removed a lot of the code I thought would be unnecessary. Thank you very much in advance.
For Each Arow As Object In ATable.Rows
For Each Brow As Object In BTable.Rows
If Brow(1) = a_ID Then
If Brow(2) = b_ID Then
Dim cbShown As Integer = Arow(5)
Dim cbAllowed As Integer = Arow(6)
Dim checkBox As New CheckBox()
End If
End If
Next
Next
checkBox.ID = Crow(0)
divcontrol.Controls.Add(checkBox)
EDIT:
Full Page_load sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (Session("studentLoggedIn") Or Session("adminLoggedIn")) Then
Routines.LogOut()
End If
If Session("adminLoggedIn") = True Then
castVote.Enabled = False
castVote.CssClass = "btnDisabled"
Dim p As New HtmlGenericControl()
p.TagName = "p"
p.InnerText = "Vote button disabled. Only students may vote."
adminMsg.Controls.Add(p)
End If
Dim ballot_ID As Integer = CType(Session.Item("ballot_ID"), Integer)
Dim ballotName As String = CType(Session.Item("ballotName"), String)
Dim ballotsAdapter As New eVoteTableAdapters.ballotsTableAdapter()
Dim ballotsTable As New eVote.ballotsDataTable
ballotsTable = ballotsAdapter.GetDataBy3getBallotsByID(ballot_ID)
Dim sectionsAdapter As New eVoteTableAdapters.sectionsTableAdapter()
Dim sectionsTable As New eVote.sectionsDataTable
sectionsTable = sectionsAdapter.GetDataBygetsectionsByBallotID(ballot_ID)
Dim candidatesAdapter As New eVoteTableAdapters.candidatesTableAdapter()
Dim candidatesTable As New eVote.candidatesDataTable
candidatesTable = candidatesAdapter.GetDataBygetCandidatesByballotID(ballot_ID)
openBallotName.InnerText = ballotName
Dim section_ID
For Each row As Object In sectionsTable.Rows
If row(1) = ballot_ID Then
section_ID = row(0)
Dim sectionName As New HtmlGenericControl()
Dim sectionDescription As New HtmlGenericControl()
Dim divcontrol As New HtmlGenericControl()
Dim br As New HtmlGenericControl()
divcontrol.Attributes("ID") = section_ID
divcontrol.Attributes("runat") = "server"
divcontrol.Attributes("style") = "border: solid;"
divcontrol.TagName = "div"
br.TagName = "br"
sectionName.TagName = "h4"
sectionDescription.TagName = "p"
mainBallotDiv.Controls.Add(divcontrol)
mainBallotDiv.Controls.Add(br)
sectionName.InnerText = row(2)
sectionDescription.InnerText = row(3)
divcontrol.Controls.Add(sectionName)
divcontrol.Controls.Add(sectionDescription)
For Each Crow As Object In candidatesTable.Rows
If Crow(1) = ballot_ID Then
If Crow(2) = section_ID Then
Dim checkBox As New CheckBox()
Dim canImg As New Image()
Dim canName As New HtmlGenericControl()
Dim canBio As New HtmlGenericControl()
Dim rmImg As New Image()
Dim rmName As New HtmlGenericControl()
Dim rmBio As New HtmlGenericControl()
Dim canBytes As Byte() = Crow(6)
Dim canBase64String As String = Convert.ToBase64String(canBytes, 0, canBytes.Length)
Dim rmBytes As Byte() = Crow(11)
Dim rmBase64String As String = Convert.ToBase64String(rmBytes, 0, rmBytes.Length)
checkBox.ID = Crow(0)
canName.TagName = "h3"
canBio.TagName = "p"
rmName.TagName = "h3"
rmBio.TagName = "p"
canName.InnerText = Crow(4) & " " & Crow(5)
canBio.InnerText = Crow(7)
canImg.ImageUrl = Convert.ToString("data:image/png;base64,") & canBase64String
canImg.Height = 120
rmName.InnerText = Crow(9) & " " & Crow(10)
rmBio.InnerText = Crow(12)
rmImg.ImageUrl = Convert.ToString("data:image/png;base64,") & rmBase64String
rmImg.Height = 120
divcontrol.Controls.Add(checkBox)
divcontrol.Controls.Add(canImg)
divcontrol.Controls.Add(canName)
divcontrol.Controls.Add(canBio)
If row(4) = True Then
divcontrol.Controls.Add(rmImg)
divcontrol.Controls.Add(rmName)
divcontrol.Controls.Add(rmBio)
End If
End If
End If
Next
End If
Next
End Sub
You will want a variable (integer) for the amount of checkboxes allowed, then another variable for the amount of checkboxes currently checked, finally a List containing the name of each checkbox, (have all these variables as class fields)
then in your event handler something like
Sub Check_Clicked(sender As Object, e As EventArgs)
checked += 1
If checked >= NumberAllowedChecked Then
For Each a As CheckBox In MyCheckBoxList
If Not CheckBox.Checked Then CheckBox.Enabled = False
Next
End If
End Sub
I am not overly familiar with VB but I think this should set you on the right track on how to implement it for yourself
Edit: you will want to add in logic for if a user unchecks a check box that it will subtract one from 'checked;

Dropdown not firing event on usercontrol

I have a dropdown list which is inside a user control on my page.
When I select an item in a gridview it fills some data including this dropdown list selecting the correspondent value to the gridview row.
Then I can change the selection, but when i try to do that the Selected Index Changed event isn't firing. At least not at first. If i select again it fires.
I'm using asp.net with VB.
I have put AutoPostback = true, I've set the Handles in the codebehind method, I've set a default empty line and set it to default selection, but I can't get it to work.
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Page.IsPostBack() Then
fillProd()
Dim cert As String = Session("var")
isFilled = Session("isFilled")
If Not IsNothing(cert) And Not isFilled Then
FillFields(cert)
End If
End If
End Sub
Private Sub fillProd()
dt = HttpContext.Current.Session("dt")
Dim row() As DataRow = dt.Select()
Dim dtProductos As New DataTable()
dtProductos.Columns.Add(New DataColumn("valorcombo", GetType(String)))
dtProductos.Columns.Add(New DataColumn("textocombo", GetType(String)))
Dim firstrow As DataRow = dtProductos.NewRow()
firstrow (0) = 0
firstrow (1) = ""
dtProductos.Rows.Add(firstrow)
For i As Integer = 0 To row.Length - 1
Dim fila As DataRow = dtProductos.NewRow()
fila(0) = row(i)("cod")
fila(1) = row(i)("text")
dtProductos.Rows.Add(fila)
Next
ddlproductos.DataSource = dtProductos
ddlproductos.DataTextField = "textocombo"
ddlproductos.DataValueField = "valorcombo"
ddlproductos.DataBind()
ddlproductos.SelectedIndex = 0
End Sub
Private Sub FillFields(cert As String)
Dim dtSubsData As DataTable = GetData(cert)
If Not IsNothing(dtSubsData) Then
Dim row As DataRow = dtSubsData.Rows(0)
ddlproductos.ClearSelection()
ddlproductos.SelectedValue = row("cod").ToString()
Session("isFilled") = True
isFilled = Session("isFilled")
End If
End Sub
Can anyone help?

Adding gridview line data into textboxes and labels

I'm trying to get the gridview details to be put into textboxes for better view and edit.
I'm listing the following code to create the gridview:
'Finds all cases that are not closed
Protected Sub listAllCases()
sqlCommand = New SqlClient.SqlCommand("SELECT TC.caseId,TS.subName,TSU.userName,TC.caseType,TC.caseRegBy,TC.caseTopic,TC.caseDesc,TC.caseSolu,TC.caseDtCreated, TC.caseStatus FROM TBL_CASE TC INNER JOIN TBL_SUBSIDIARY_USER TSU ON TC.caseUser = TSU.userID INNER JOIN TBL_SUBSIDIARY TS on TSU.usersubId = TS.subId WHERE TC.caseStatus = 0 order by caseId")
sqlCommand.Connection = sqlConnection
sqlConnection.Open()
'sqlCommand.Parameters.AddWithValue("#subID", Me.caseSub.SelectedItem.Value)
Dim dr As SqlClient.SqlDataReader
dr = sqlCommand.ExecuteReader
If dr.HasRows Then
allCases.DataSource = dr
allCases.DataBind()
Else
allCases.DataSource = Nothing
allCases.DataBind()
End If
dr.Close()
sqlConnection.Close()
End Sub
Then I use the a function on the gridview onselectindexchanged and Writes this:
Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = allCases.SelectedRow
txtcase.Text = row.Cells(1).Text()
txtsub.Text = row.Cells(2).Text
txtuser.Text = row.Cells(3).Text
oDato.Text = row.Cells(9).Text
lDato.Text = "Saken er ikke lukket!"
txttype.Text = row.Cells(4).Text.ToString
txtregBy.Text = row.Cells(5).Text.ToString
txttopic.Text = row.Cells(6).Text
txtDesc.Text = row.Cells(7).Text
txtSolu.Text = row.Cells(8).Text
lblinfo.Text = row.Cells(6).Text
End Sub
I only get it to display cells 1 to 9. Means cell 4 to 8 is not listed or being blank, even though i know it should contain data.
Any tips or Clues is very appreciated!
Like This ?
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As
TextBox1.text = DataGridView1.Rows(e.Index).Cells(0).value.toString
TextBox2.text = DataGridView1.Rows(e.Index).Cells(1).value.toString
TextBox3.text = DataGridView1.Rows(e.Index).Cells(2).value.toString
TextBox4.text = DataGridView1.Rows(e.Index).Cells(3).value.toString
TextBox5.text = DataGridView1.Rows(e.Index).Cells(4).value.toString
TextBox6.text = DataGridView1.Rows(e.Index).Cells(5).value.toString
TextBox7.text = DataGridView1.Rows(e.Index).Cells(6).value.toString
TextBox8.text = DataGridView1.Rows(e.Index).Cells(7).value.toString
TextBox9.text = DataGridView1.Rows(e.Index).Cells(8).value.toString
TextBox10.text = DataGridView1.Rows(e.Index).Cells(9).value.toString
End Sub
This will display all the information in the row by clicking the record...
e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
sorry for that ...
by clicking the data the (e.Index) will locate in which DataGridView.Rows(), then the cells.(n) and etc... will get your data
ok. i got it right, finally. the code i used to get it work is as follows:
Protected Sub allCases_OnSelectedIndexChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = allCases.SelectedRow
txtcase.Text = row.Cells(1).Text()
txtsub.Text = row.Cells(2).Text.ToString
txtuser.Text = row.Cells(3).Text
oDato.Text = row.Cells(9).Text
txtDesc.Text = TryCast(row.FindControl("lblcaseDesc"), Label).Text
txtSolu.Text = TryCast(row.FindControl("lblcaseSolu"), Label).Text
end sub
this means I need to fetch the boundfields and templatefields differently.
Anyhow thanks for the reponse.

Unable to show the saved data in gridview

I have a dropdown in gridview, which gets data through web method,but after saving data, i am unable to show saved data in gridview.
Here is the code behind for gridview bind through web method:
Private Sub BindData()
Dim objTable As New DataTable("ProjectInfoClass")
objTable = objWebService.BindProjectInfo
projectInfoList.Clear()
For Each dr As DataRow In objTable.Rows
projectInfoList.Add(New ProjectInfoClass With {.ProjectNumber = dr("ProjectNumber").ToString(), .ProjectId = dr("ProjectId").ToString(), .ProjectName = dr("ProjectName").ToString(), .ProjectModifiedDate = dr("ProjectModifiedDate").ToString(), .RecordUpdatedDate = dr("RecordUpdatedDate").ToString(), .ProjectLocation = dr("ProjectLocation").ToString(), .LocationServerName = dr("LocationServerName").ToString(), .ProjectModifiedBy = dr("ProjectModifiedBy").ToString(), .DBServer = dr("DBServer").ToString(), .DBName = dr("DBName").ToString(), .Flag = Nothing})
Next
GridView1.DataSource = objTable
GridView1.DataBind()
End Sub
Save method
For Each objectList In projectInfoList
If objectList.Dirty = True And objectList.Flag = Nothing Then
objWebService.UpdateProjectInfo(objectList)
Label1.Text = "Record updated successfully"
ElseIf objectList.Flag = "I" And objectList.Dirty = True Then
objWebService.InsertProjectInfo(objectList)
Label1.Text = "Record inserted successfully"
End If
Next
BindData()
btnEdit.Enabled = True
btnSave.Enabled = False
btnAddNewRow.Enabled = False
End Sub
Here is the code behind to bind dropdown which calls the web method:
Public Sub BindDataDropDown()
For Each grdRow As GridViewRow In GridView1.
Dim dropDown As DropDownList = DirectCast(GridView1.Rows(grdRow.RowIndex).Cells(7).FindControl("ddlProjectModifiedBy"), DropDownList)
dropDown.DataSource = objWebService.BindDropDown()
dropDown.DataValueField = "EmpId"
dropDown.DataTextField = "EmpName"
dropDown.DataBind()
Next
End Sub
rowdatabound
Protected Sub ddlProjectModifiedBy_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
BindDataDropDown()
End Sub
indexchange
Protected Sub ddlProjectModifiedBy_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gv As DropDownList = TryCast(sender, DropDownList)
Dim row As GridViewRow = gv.Parent.NamingContainer
Dim rowindex As Integer = row.RowIndex
projectInfoList.Item(rowindex).ProjectModifiedBy = gv.SelectedItem.ToString()
projectInfoList.Item(rowindex).Dirty = True
End Sub
What should i write in the rowbound event of grid to hold selected data of dropdown in gridview?
Call the drop down binding method BindDataDropDown() after you have successfully saved the changes to the database.

Dynamic gridview columns event problem

i have a GridView (selectable) in which I want to generate a dynamic GridView in a new row BELOW the selected row.
I can add the row and gridview dynamically in the Gridview1 PreRender event. I need to use this event because:
_OnDataBound is not called on every postback (same for _OnRowDataBound)
_OnInit is not possible because the 'Inner table' for the Gridview is added after Init
_OnLoad is not possible because the 'selected' row is not selected yet.
I can add the columns to the dynamic GridView based on my ITemplate class.
But now the button events won't fire.... Any suggestions?
The dynamic adding of the gridview:
Private Sub GridView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PreRender
Dim g As GridView = sender
g.DataBind()
If g.SelectedRow IsNot Nothing AndAlso g.Controls.Count > 0 Then
Dim t As Table = g.Controls(0)
Dim r As New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal)
Dim c As New TableCell
Dim visibleColumnCount As Integer = 0
For Each d As DataControlField In g.Columns
If d.Visible Then
visibleColumnCount += 1
End If
Next
c.ColumnSpan = visibleColumnCount
Dim ph As New PlaceHolder
ph.Controls.Add(CreateStockGrid(g.SelectedDataKey.Value))
c.Controls.Add(ph)
r.Cells.Add(c)
t.Rows.AddAt(g.SelectedRow.RowIndex + 2, r)
End If
End Sub
Private Function CreateStockGrid(ByVal PnmAutoKey As String) As GridView
Dim col As Interfaces.esColumnMetadata
Dim coll As New BLL.ViewStmCollection
Dim entity As New BLL.ViewStm
Dim query As BLL.ViewStmQuery = coll.Query
Me._gridStock.AutoGenerateColumns = False
Dim buttonf As New TemplateField()
buttonf.ItemTemplate = New QuantityTemplateField(ListItemType.Item, "", "Button")
buttonf.HeaderTemplate = New QuantityTemplateField(ListItemType.Header, "", "Button")
buttonf.EditItemTemplate = New QuantityTemplateField(ListItemType.EditItem, "", "Button")
Me._gridStock.Columns.Add(buttonf)
For Each col In coll.es.Meta.Columns
Dim headerf As New QuantityTemplateField(ListItemType.Header, col.PropertyName, col.Type.Name)
Dim itemf As New QuantityTemplateField(ListItemType.Item, col.PropertyName, col.Type.Name)
Dim editf As New QuantityTemplateField(ListItemType.EditItem, col.PropertyName, col.Type.Name)
Dim f As New TemplateField()
f.HeaderTemplate = headerf
f.ItemTemplate = itemf
f.EditItemTemplate = editf
Me._gridStock.Columns.Add(f)
Next
query.Where(query.PnmAutoKey.Equal(PnmAutoKey))
coll.LoadAll()
Me._gridStock.ID = "gvChild"
Me._gridStock.DataSource = coll
AddHandler Me._gridStock.RowCommand, AddressOf Me.gv_RowCommand
Me._gridStock.DataBind()
Return Me._gridStock
End Function
The ITemplate class:
Public Class QuantityTemplateField : Implements ITemplate
Private _itemType As ListItemType
Private _fieldName As String
Private _infoType As String
Public Sub New(ByVal ItemType As ListItemType, ByVal FieldName As String, ByVal InfoType As String)
Me._itemType = ItemType
Me._fieldName = FieldName
Me._infoType = InfoType
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Select Case Me._itemType
Case ListItemType.Header
Dim l As New Literal
l.Text = "<b>" & Me._fieldName & "</b>"
container.Controls.Add(l)
Case ListItemType.Item
Select Case Me._infoType
Case "Button"
Dim ib As New Button()
Dim eb As New Button()
ib.ID = "InsertButton"
eb.ID = "EditButton"
ib.Text = "Insert"
eb.Text = "Edit"
ib.CommandName = "Edit"
eb.CommandName = "Edit"
AddHandler ib.Click, AddressOf Me.InsertButton_OnClick
AddHandler eb.Click, AddressOf Me.EditButton_OnClick
container.Controls.Add(ib)
container.Controls.Add(eb)
Case Else
Dim l As New Label
l.ID = Me._fieldName
l.Text = ""
AddHandler l.DataBinding, AddressOf Me.OnDataBinding
container.Controls.Add(l)
End Select
Case ListItemType.EditItem
Select Case Me._infoType
Case "Button"
Dim b As New Button
b.ID = "UpdateButton"
b.Text = "Update"
b.CommandName = "Update"
b.OnClientClick = "return confirm('Sure?')"
container.Controls.Add(b)
Case Else
Dim t As New TextBox
t.ID = Me._fieldName
AddHandler t.DataBinding, AddressOf Me.OnDataBinding
container.Controls.Add(t)
End Select
End Select
End Sub
Private Sub InsertButton_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("insert click")
End Sub
Private Sub EditButton_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("edit click")
End Sub
Private Sub OnDataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim boundValue As Object = Nothing
Dim ctrl As Control = sender
Dim dataItemContainer As IDataItemContainer = ctrl.NamingContainer
boundValue = DataBinder.Eval(dataItemContainer.DataItem, Me._fieldName)
Select Case Me._itemType
Case ListItemType.Item
Dim fieldLiteral As Label = sender
fieldLiteral.Text = boundValue.ToString()
Case ListItemType.EditItem
Dim fieldTextbox As TextBox = sender
fieldTextbox.Text = boundValue.ToString()
End Select
End Sub
End Class
Oh my oh my, I went to MVC, anybody reading this question should do the same :)

Resources