Posts

Easy Nested Datagrid

Nested Grid Example ASPX Page <asp:datagrid id ="dgBids" onItemCommand ="commandDGBid" headerStyle-CssClass ="tdheaders" cellpadding ="5" runat ="server" autogeneratecolumns ="false"> < columns > < asp : BoundColumn dataField ="company" headertext ="Company"></ asp : BoundColumn > < asp : BoundColumn dataField ="bidID" visible ="false"></ asp : BoundColumn > < asp : ButtonColumn buttonType ="LinkButton" dataTextField ="bidid" CommandName ="bid" headertext ="Bid"></ asp : ButtonColumn > < asp : BoundColumn dataField ="seasondesc" headertext ="Season"></ asp : BoundColumn > < asp : BoundColumn dataField ="style" headertext ="Style"></ asp : BoundColumn > < asp : BoundColumn dataField ="styledescription"...

No Query Strings Needed

.NET allows you to reference most anything from one page to any page. An example: Page1.aspx Public Shared MyVariableThatIWant_ToPass as string = "secret information" OnAnyOtherPage. aspx Dim TheSecretFromPage1 as string TheSecretFromPage1 = MyProject.Page1. MyVariableThatIW_antToPass

Raising Events

In Default.aspx I have a user control ( < WI : editBOM runat ="server" id ="ctlEdit" />)  I want to refresh  the ctlEdit dropdownlist when another control fires (BOM.ascx)   So in DEFAULT.aspx I add this sub Private Sub ctlNew_drpBOM_Change() Handles ctlNew.drpBOM_Change ctlEdit.drpbomChange() End Sub In the EDITBOM.ASCX file I add this subroutine essentially rebinding the dropdownlist Public Sub drpbomChange() drpBOM.DataSource = VendorBid_Data.itemAttributesvb.getValidBOMStyles() drpBOM.DataBind() drpBOM.Items.Insert(0, "Choose Style" ) End Sub In the BOM.ASCX file I declare the event and raise the event: Public Event drpBOM_Change() I raise the event at the point I want to fire it.... RaiseEvent drpBOM_Change() Thus we have a page that holds two controls - when one dropdownlist or event fires then the other control dropdownlist is refreshed.  This enables me to load up my controls on the page but if c...

DorpDownList in DL set by value in Database

Sub dlComponent_databind( ByVal sender As Object , ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Dim drpMarket As DropDownList = CType (e.Item.FindControl( "drpStatus" ), DropDownList) drpMarket.Items.Insert(0, "No Selection Specified" ) drpMarket.SelectedValue = Trim(e.Item.DataItem.componentStatus) Dim drpCo As DropDownList = CType (e.Item.FindControl( "drpCompany" ), DropDownList) drpCo.Items.Insert(0, "No Selection Specified" ) drpCo.SelectedValue = Trim(e.Item.DataItem.company) End Sub

Keeping Dynamic Controls Dynamic

Part of the issue with including User Controls in a page by adding them in the top of the page like this: <% @ Register TagPrefix ="HMD" TagName ="Assortment" Src ="~/Controls/assortments.ascx" %> is that if the content is something like say a shopping cart or dropdownlists generated from a database or something where the state and the refreshed load is terribly important  - a solution is to load the control dynamically based on an event.  Dim the control and add it to the page via a literal or panel or table cell or some other object that could house it.  This assures that the control is loaded fresh everytime it needs to be. Dim ctlStoreSku As Control = LoadControl( "controls/skuweekly.ascx" ) myPanel.Controls.Add(ctlStoreSku) myPanel.Visible = True That's  it....

Fixed Datagrid Headers

Quick and dirty way to make Datagrid Headers stay at the top of the page while your viewers are scrolling down the page can be accomplished with a little CSS   Add this style:       .DataGridFixedHeader { POSITION : relative ;  TOP : expression(this.offsetParent.scrollTop) ; BACKGROUND-COLOR : white } Add this to your Datagrid properties:       HeaderStyle-CssClass =" DataGridFixedHeader " And Voila ... you have a header that stays in place.

Errors Errors Errors

We would always prefer to avoid all errors but if one happens we certainly want to know about it. Adding an error handler to the Global.asax file is slick - easy and works beautifully..... here is what you need: Sub Application_Error( ByVal sender As Object , ByVal e As EventArgs) Try Dim strFrom As String = System.Configuration.ConfigurationManager.AppSettings( "EmailFrom" ) Dim strTo As String = System.Configuration.ConfigurationManager.AppSettings( "EmailTo" ) Dim msg As System.Net.Mail.MailMessage Dim smtp As New System.Net.Mail.SmtpClient( " mail.yourmailserver.com " ) msg = New System.Net.Mail.MailMessage(strFrom, strTo, "Page Error My Application Name" , BuildMessage()) msg.IsBodyHtml = True smtp.Credentials = New System.Net.NetworkCredential( "Username" , "password" , " mail.myserver.com " ) smtp.Send(msg) Catch ex As Exception End Try End Sub The buildMessage Function in the global.asax...