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