2008-09-16
2008-08-01
2008-06-29
2008-05-11
2008-04-19
2008-01-15
2007-11-30
2007-09-27
2007-09-26
2007-09-25
2007-09-24
2007-09-21
2007-09-19
2007-09-14
2007-08-20
2007-06-29
2007-06-12
» Edit navigation panel
Protected Sub dgSurveys_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles dgSurveys.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim hyp As HyperLink = CType(e.Row.Cells(0).Controls(0), HyperLink) Dim url As String = hyp.NavigateUrl Dim split1 As String() = url.Split("?") Dim finalUrl As String = split1(0) If split1.Length > 1 Then finalUrl &= "?" Dim split2 As String() = split1(1).Split("&") Dim query As String Dim isFirstElement As Boolean = True For Each query In split2 If isFirstElement = False Then finalUrl &= "&" End If If query.Split("=").Length > 1 Then finalUrl &= query.Split("=")(0) & "=" & Server.UrlEncode(query.Split("=")(1)) Else finalUrl = finalUrl.Substring(0, finalUrl.Length - 1) finalUrl &= Server.UrlEncode("&" & query) End If isFirstElement = False Next End If hyp.NavigateUrl = finalUrl
If DirectCast(e.Row.FindControl("lblDueCross"), Label).Text = "1" Then e.Row.Cells.Item(3).ForeColor = Drawing.Color.Red End If dgSurveys.DataKeys(e.Row.RowIndex).Item(2).ToString()
'Dim strKeyword As String = dgSurveys.DataKeys(e.Row.RowIndex).Item(14).ToString 'If strKeyword = "Gas Warm Air Furnace by Efficiency, State, Configuration Report" Then
'End If
Dim tempStr As String = DirectCast(e.Row.FindControl("lblFreqType"), Label).Text ' Code to Disable if the selected company did not fill ' the monthly survey corresponding to the Quarterly survey If ChangeDBNullToEmptyString(Right(tempStr, (tempStr.Length - 1)).ToString) <> "" Then If Left(tempStr, 1) = "2" Then ' Check Whether Survey is Quarterly or not Dim count As Int16 Dim t As String = dgSurveys.DataKeys(e.Row.RowIndex).Values(2).ToString Dim strsql As New System.Text.StringBuilder Try strsql.Append("GetThreeMonthlySurveyID ") strsql.Append(PrepareString(t) & COMMA) strsql.Append(PrepareString(Right(tempStr, (tempStr.Length - 1)).ToString)) sqlcmd.CommandTimeout = 1000 count = getSingleValue(sqlcmd, strsql.ToString) Catch ex As Exception End Try
If count > 0 Then 'e.Row.Cells.Item(0).Enabled = False e.Row.Cells.Item(0).Attributes.Add("style", "cursor:hand") Dim txt As String = CType(e.Row.Cells.Item(0).Controls(0), HyperLink).Text e.Row.Cells.Item(0).Controls.Remove(e.Row.Cells.Item(0).Controls(0)) e.Row.Cells.Item(0).Text = txt 'e.Row.Cells.Item(0).CssClass = "GridGray" e.Row.Cells.Item(0).ForeColor = Drawing.Color.Gray e.Row.Cells.Item(0).Attributes.Add("onclick", "alert('Please fill out the corresponding monthly survey first.')") e.Row.Cells.Item(4).Enabled = False e.Row.Cells.Item(6).Enabled = False e.Row.Cells.Item(5).Text = "Please fill out the corresponding monthly survey first" e.Row.Cells.Item(5).ForeColor = Drawing.Color.Red End If End If End If Dim tblCellControl As System.Web.UI.WebControls.ImageButton = e.Row.Cells.Item(e.Row.Cells.Count - 1).FindControl("img1") tblCellControl.Attributes.Add("onclick", "return getConfirm('Please note that uploading the Excel data will overwrite any data entered in the online form.\nDo you want to proceed?');")
'Dim tblCellControl1 As System.Web.UI.WebControls.ImageButton = e.Row.Cells.Item(e.Row.Cells.Count - 1).FindControl("imgDownload") 'tblCellControl1.Attributes.Add("onclick", "return excelDownload();")
End If End Sub
==========================================================================
Session.Abandon() -- If you call this method Session_End will be fired and in the next request Session_Start will be fired.
Session.Clear() - it will just clear the session data with out killing the session data.
===================================================================== Debuggin Javascript in vs
1) Open Internet Explorer, Tools menu -> Internet Option Dialog box. - Click on Advance Tab. - Clear the checkbox: Disable Script Debugging(Internet Explorer) - Clear the checkbox: Disable Script Debugging(Other)
2) Use the keyword "debugger" in your script as breakpoint from where you want to start debugging.
===========================================================================
Explain DataView It provides a means to filter and sort data within a data table. Example: DataView myDataView = new DataView(myDataSet.Tables["Customers"]);
// Sort the view based on the FirstName column myDataView.Sort = "CustomerID";
// Filter the dataview to only show customers with the CustomerID of ALFKI myDataView.RowFilter = "CustomerID='ALFKI'"; ===========================================================================
To download a Google page… private void Form1_Load(object sender, EventArgs e){ // Create a request for the URL. WebRequest request = WebRequest.Create("http://www.google.com"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); StreamWriter sw = new StreamWriter("c:\\temp.html"); sw.Write(responseFromServer); sw.Close(); reader.Close(); dataStream.Close(); response.Close();} =========================================================================== 'Disabling back button after logout from a page
history.forward();
add this code in logout click event
Page.RegisterStartupScript("Disable","<script> <script>javascript:window.history.forward(1);</script></script>"); =========================================================================== ' To enable or Disable in a grid Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then
If salary> 0 Then ' this is the condition based on you want to enable or disable e.Row.Cells.Item(0).CssClass = "GridGray" e.Row.Cells.Item(0).ForeColor = Drawing.Color.Gray ' This is to change the first cell font color to red e.Row.Cells.Item(4).Enabled = False ' Make the 4th column disable
' if you want to change whole row e.Row.Enabled = False End If End If
End Sub
=========================================================================== ' To get the Last day of month Dim currentDate As DateTime = DateTime.Now.Date Dim sDate As DateTime = currentDate.Subtract(New TimeSpan(currentDate.Day - 1, 0, 0, 0, 0)).ToShortDateString() Dim EndDate As String=sDate.Add(New TimeSpan(DateTime.Now.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)-1, 0, 0, 0, 0)).ToShortDateString()
'To get the last day of month different method
Public Function ComputeLastDayOfMonth(ByVal TheDate As Variant) As Integer LastDayOfMonth = DatePart("d", DateAdd("d", -1, DateAdd("m", 1, DateAdd("d", - DatePart("d", TheDate) + 1, TheDate)))) End Function
intX = ComputeLastDayOfMonth("2/2000")
=========================================================================== 'VB Code to Fill the Combo box
Protected Sub FillSurveys() sqlStr = "SELECT SurveyCode,SurveyName FROM ValidSurveys" 'sqlcmd = New SqlCommand(sqlStr, sqlcon) dAdapter.SelectCommand = New SqlCommand(sqlStr, sqlcon) dAdapter.Fill(dSet) Dim count As Integer = dSet.Tables(0).Rows.Count cmbSurveys.DataBindings.Clear() cmbSurveys.DisplayMember = "SurveyName" cmbSurveys.ValueMember = "SurveyCode" cmbSurveys.DataSource = dSet.Tables(0) End Sub
'C# Code to Fill the Combo box protected void FillSurveys() { sqlStr = "SELECT SurveyCode,SurveyName FROM ValidSurveys"; dAdapter.SelectCommand = new SqlCommand(sqlStr, sqlcon); dAdapter.Fill(dSet); int count = dSet.Tables(0).Rows.Count; cmbSurveys.DataBindings.Clear(); cmbSurveys.DisplayMember = "SurveyName"; cmbSurveys.ValueMember = "SurveyCode"; cmbSurveys.DataSource = dSet.Tables(0); }
=========================================================================== ' Function to Send mail in asp.net with attachment file
Public Sub SendMail(ByVal smtpMailServer As String, ByVal strFrom As String, ByVal strPwd As String, ByVal strTo As String, ByVal strSubject As String, ByVal Message As String, ByVal Attachment As String) Dim objMailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage Dim SmtpMail As System.Web.Mail.SmtpMail objMailMessage.From = strFrom objMailMessage.To = strTo objMailMessage.Subject = strSubject objMailMessage.Body = Message objMailMessage.BodyFormat = System.Web.Mail.MailFormat.Html objMailMessage.Priority = System.Web.Mail.MailPriority.Normal SmtpMail.SmtpServer = smtpMailServer '"YourMailServerName" If Attachment.Length > 0 Then If System.IO.File.Exists(Attachment) Then objMailMessage.Attachments.Add(Attachment) End If End If objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1) objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strFrom) objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPwd)
SmtpMail.Send(objMailMessage)
End Sub =========================================================================== ' Functino to download a file Private Sub downloadFile(ByVal path As String) If path <> "" Then Dim file As System.IO.FileInfo = New System.IO.FileInfo(path) '-- if the file exists on the server If file.Exists Then 'set appropriate headers 'Try Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name) Response.AddHeader("Content-Length", file.Length.ToString()) Response.ContentType = "Application/octet-stream" Response.WriteFile(file.FullName) Response.End() 'Catch ex As Exception ' lblerrmsg.Text = ex.Message 'End Try Else lblerrmsg.Text = "This file does not exist" 'if file does not exist End If 'nothing in the URL as HTTP GET Else lblerrmsg.Text = "Please provide a file to download." End If
private void downloadFile(string path) { if (path != "") { System.IO.FileInfo file = new System.IO.FileInfo(path); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "Application/octet-stream"; Response.WriteFile(file.FullName); Response.End(); } else { lblerrmsg.Text = "This file does not exist"; } } else { lblerrmsg.Text = "Please provide a file to download."; } }
=========================================================================== ' This is used to sort grid it works for 1000 records only Public Sub FillGridViewUsingdatasource(ByRef gv As GridView, ByRef sqlcon As String, ByRef strsql As String) Dim ds As New SqlDataSource(sqlcon, strsql) gv.DataSource = ds gv.DataBind() End Sub
FillGridViewUsingdatasource(GVReport, System.Configuration.ConfigurationManager.ConnectionStrings("NewMcsWeblinks").ToString, strsql)
Set GridView Properties
AllowSorting True EnableSortingAndPagingCallBacks True
and BoundFields properties set SortExpression as Datafield name for all Bound fields ===========================================================================
‘ Function to Check a string is upper case or not Public Function checkUpper(ByVal str As String) As Boolean If Strings.StrComp(str, Strings.UCase(str)) = 0 Then Return True Else Return False End If End Function