This worked well for me. I created the TABLE in markup [MAKE SURE ITS AN ASP:TABLE with the runat server tag].
Then you can manipulate it from code-behind like so:
TableRow tr = new TableRow();
TableCell tc = new TableCell();
Label label2 = new Label();
label2.Text = "LAJLKFJDSLJFLKDF";
tc.Controls.Add(label2);
tr.Cells.Add(tc);
MyTable.Rows.Add(tr);
Hope this helps!
I am not even going to try — here is the best and most complete description of the Page Lifecycle.
http://69.10.233.10/KB/aspnet/ASPNET_Page_Lifecycle.aspx (very nice and thanks UsualDosage)
Although I will list the Acronym that may help those of you who just need a quick reminder…. try this
- S - Start
- I - Initialize
- L - Load
- V - Validate
- E - Event Handling
- R - Render
caio
This one almost killed me… I have a nested repeater and could not for the life of me figure out how to find the controls in the nested repeater…
I was doing ONE thing wrong… instead of placing the ItemDataBound event declaration in the Parents ItemDataBound event… I had to put it in the ItemCreated event… and that was it. After that I could easily find my controls.
Protected Sub RepeaterPARENT_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterPARENT.ItemCreated
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim repeaterCHILD As Repeater = New Repeater
repeaterCHILD = TryCast(e.Item.FindControl("RepeaterCHILD"), Repeater)
AddHandler repeaterCHILD.ItemDataBound, AddressOf repeaterCHILD_ItemDataBound
End If
End Sub
Protected Sub repeaterCHILD_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Header Then
Qty = 0.0
End If
If CType(e.Item.FindControl("HiddenQuantity"), HiddenField) IsNot Nothing Then
Dim HiddenQuantity As HiddenField = CType(e.Item.FindControl("HiddenQuantity"),
HiddenField)
Qty += CDbl(HiddenQuantity.Value)
End If
If CType(e.Item.FindControl("LabelQTYSubtotal"), Label) IsNot Nothing Then
Dim LabelNew As Label = New Label
LabelNew = CType(e.Item.FindControl("LabelQTYSubtotal"), Label)
LabelNew.Text = Qty.ToString
End If
End Sub
onBlur=”javascript:this.value=this.value.toUpperCase();”
Of course, this could be done the opposite way with .toLowerCase();
This forces the textbox to all upper case as the user leaves, works well.
Example Scenario:
Lets say you have a form that has a BACK link. You want to make sure that if the user has made any changes on that form and they click the BACK that they REALLY want to leave the page.
So on your input boxes you can place an onChange event that sets a global variable to true (yes this form has been changed!)… i.e. onchange=”g_bformChanged=true;”
Then on your back button just fire off your function that checks to see if the form has changed… using your CONFIRM box to get a confirmation from your user.
<script type="text/javascript">
//Global
var g_bformChanged = false;
function checkForSaveNeed() {
if (g_bformChanged) {
var confirmLeave = confirm("No changes will be saved. Are you sure you want to leave?");
if (confirmLeave == true) {
window.location = "ManageSchools.aspx"
}
}
else
window.location = "ManageSchools.aspx";
}
</script>
This structure keeps coming up :
dsSchools = mydata
'Create table to bind to dataGrid
Dim dt As New DataTable
Dim nameCol, activeCol As New DataColumn
dt.Columns.Add(nameCol)
dt.Columns.Add(activeCol)
Dim dRow As DataRow = dt.NewRow
For Each dr As DataRow In dsSchools.Tables(0).Rows
If Not dr("title") Is DBNull.Value Then dRow(nameCol) = dr("title")
If Not dr("IsActive") Is DBNull.Value Then dRow(activeCol) = dr("isActive").ToString
dt.Rows.Add(dRow)
Next
BEGIN TRAN
–Delete from table.
DELETE FROM blah where blah
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
return -1
END
–NOW delete from other table
DELETE FROM blah2 where blah2
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
return -1
END
COMMIT TRAN
For Each loops is a read-only loop! In other words, you cannot mutate the reference you are referring to.
A For Next loop allows mutation, plus I like For Next’s because they allow me to determine if I am on the final loop or not…
Examples,
For x as integer = 0 to myStringArray.Count - 1
myStringArray(x) += “add this to end”
if x = myStringArray.Count - 1 then myStringArray(x) += “, and this is the last element!”
Next
cheers!
t
I JUST FOUND THIS INTERESTING, THIS MAY OR MAY NOT BE HELPFUL… BUT I STARTED PLAYING WITH AN ARRAYLIST IN VB AND FOUND OUT THAT YOU CAN HOLD MULTIPLE TYPES INSIDE OF A SINGLE ARRAY.
TAKE A LOOK AT THE CODE BELOW - SEE THAT I STORE A STRING, 2 INTEGERS, AND A BOOLEAN ALL WITHIN THE SAME ARRAYLIST. I THINK THAT’S COOL…BUT I’M A DORK.
EVEN COOLER, YOU WILL SEE THAT THE ARRAYLIST CAN MAKE DECISIONS BASED ON THE TYPE IT IS LOOKING AT… (IS THE BOOLEAN TRUE OR FALSE?, DOES THE ARRAYLIST CONTAIN THIS STRING?, WHAT IS THE RESULT OF ADDING THIS ITEM TO THIS ITEM, AND CONCATENATING A STRING AND AN INT)
I IMAGINE THIS IS PROBABLY A TERRIBLE PRACTICE BECAUSE YOU WOULD HAVE TO KNOW THE TYPE AT EACH ELEMENT, BUT INTERESTING NONE THE LESS.
Dim arrList As New ArrayList
Dim theString As String = "TR"
Dim theInt As Integer = 54
Dim theBool As Boolean = False
Dim theInt2 As Integer = 46
arrList.Add(theString)
arrList.Add(theInt)
arrList.Add(theBool)
arrList.Add(theInt2)
MessageBox.Show(arrList(0))
MessageBox.Show(arrList(1))
MessageBox.Show(arrList(2))
'Now to tests
MessageBox.Show(arrList.Contains("TE")) 'Should be false
MessageBox.Show(arrList.Contains(54)) 'Should be true
MessageBox.Show(arrList.Contains(False)) 'Should be true
MessageBox.Show(arrList(1) + arrList(3))
MessageBox.Show(arrList(0) & arrList(1))
'MessageBox.Show(arrList(0))
'MessageBox.Show(arrList(1))
'MessageBox.Show(arrList(2))
CHEERS!
T
I would just like to point out two areas where both C# and VB.Net beat the other one in the usage of arrays.
C# PRO:
You can redefine your array simply in C# by simply reinitializing the array:
//Declare array
int[ ] myInts = new int[20];
//Now reinitialize like this
myInts = new int[40];
In VB you have to reinitialize with the ReDim keyword
Dim myInts(20)
ReDim myInts(40)
Not a big deal but I give the better implementation to C# on this one…however.
===========================================
In VB.Net you can actually reinitialize an array AND MAINTAIN the data within the current array!
This is accomplished by using the ‘Preserve’ keyword. (this is not available in C#)
'Declare array
Dim myInts() As Integer = { 1,2,3,4 }
'Resize array and keep the data with the Preserve keyword
ReDim Preserve myInts(20)