border: 0
cellspacing: 0
cellpadding: 0
FONT-SIZE: 9pt; MARGIN: 2px 2px 2px 5px; FONT-FAMILY: Arial
I'm a computer programmer based in Roche, St. Austell, Cornwall with over 7 years of experience in IT. I mostly work with ASP.NET, MS SQL Server and MS Access. This blog contains the knowledge I've gained over the years. Posted mostly as rough notes, I welcome any comments. I hope you might find my blog useful.
Search
Subscribe via email
Thursday, October 21, 2010
formview final formatting
formview formatting
cell width 0% for names of cols
put adjuster label in a row below, width 0%, cell 0%
txtboxes size same as in filter
val summary height 0%
set color and margins of page body document
<body style="color: black;margin-left:0px; margin-top:0px;margin-bottom:0px;margin-right:0px" bgcolor="#000000" >
Reportviewer overlapping on panel and other controls at bottom
Resolved it by adding an invisible label with length adjusted accordingly and making it visible along with the reportviewer.
Autokey primary key column selected as sequence in objectdatasource reportviewer
open dataset1.xsd
edit it
add
<xs:element name="Autokey1" msdata:ReadOnly="true" msdata:Caption="Autokey" msprop:Generator_UserColumnName="Autokey1" msprop:Generator_ColumnPropNameInRow="Autokey1" msprop:Generator_ColumnVarNameInTable="columnAutokey1" msprop:Generator_ColumnPropNameInTable="Autokey1Column" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
full listing
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DataSet1" targetNamespace="http://tempuri.org/DataSet1.xsd" xmlns:mstns="http://tempuri.org/DataSet1.xsd" xmlns="http://tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
<Connection AppSettingsObjectName="Web.config" AppSettingsPropertyName="Lungar ProjectConnectionString" ConnectionStringObject="" IsAppSettingsProperty="True" Modifier="Assembly" Name="Lungar ProjectConnectionString (Web.config)" ParameterPrefix="@" PropertyReference="AppConfig.System.Configuration.ConfigurationManager.0.ConnectionStrings.Lungar ProjectConnectionString.ConnectionString" Provider="System.Data.SqlClient">
</Connection>
</Connections>
<Tables>
<TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="DataTableAdapter" GeneratorDataComponentClassName="DataTableAdapter" Name="Data" UserDataComponentName="DataTableAdapter">
<MainSource>
<DbSource ConnectionRef="Lungar ProjectConnectionString (Web.config)" DbObjectType="Unknown" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="False" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="False" UserGetMethodName="GetData" UserSourceName="Fill">
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="True">
<CommandText>SELECT
CONVERT(VARCHAR, (CASE WHEN Autokey IS NULL THEN
(SELECT TOP 1 '' AS Autokey
FROM Data) ELSE Autokey END), 1) AS Autokey,
CONVERT(VARCHAR, (CASE WHEN Province IS NULL THEN
(SELECT TOP 1 '' AS Province
FROM Data) ELSE Province END), 1) AS Province,
CONVERT(VARCHAR, (CASE WHEN District IS NULL THEN
(SELECT TOP 1 '' AS District
FROM Data) ELSE District END), 1) AS District,
CONVERT(VARCHAR, (CASE WHEN Hospital IS NULL THEN
(SELECT TOP 1 '' AS Hospital
FROM Data) ELSE Hospital END), 1) AS Hospital,
CONVERT(VARCHAR, (CASE WHEN Caterer_Name IS NULL THEN
(SELECT TOP 1 '' AS Caterer_Name
FROM Data) ELSE Caterer_Name END), 1) AS Caterer_Name,
CONVERT(CHAR(11), (CASE WHEN Date_of_Entry IS NULL THEN
(SELECT TOP 1 '2/5/1981' AS Date_of_Entry
FROM Data) ELSE Date_of_Entry END), 106) AS Date_of_Entry,
CASE WHEN Date_of_Entry = '01 Jan 1900' THEN
(SELECT TOP 1 '' AS Date_of_Entry
FROM Data) ELSE DATENAME(WEEKDAY, Date_of_Entry) END AS Week,
CONVERT(VARCHAR, (CASE WHEN No_of_Daigs IS NULL
THEN
(SELECT TOP 1 '' AS No_of_Daigs
FROM Data) ELSE No_of_Daigs END), 1) AS No_of_Daigs, CONVERT(VARCHAR, (CASE WHEN Food_Item IS NULL THEN
(SELECT TOP 1 '' AS Food_Item
FROM Data) ELSE Food_Item END), 1) AS Food_Item,
No_of_Rotis,
CONVERT(VARCHAR, (CASE WHEN No_of_Bene_Male IS NULL THEN
(SELECT TOP 1 '' AS No_of_Bene_Male
FROM Data) ELSE No_of_Bene_Male END), 1) AS No_of_Bene_Male, CONVERT(VARCHAR, (CASE WHEN No_of_Bene_Female IS NULL
THEN
(SELECT TOP 1 '' AS No_of_Bene_Female
FROM Data) ELSE No_of_Bene_Female END), 1) AS No_of_Bene_Female, CONVERT(VARCHAR, (CASE WHEN Daily_Cost_Per_Person IS NULL
THEN
(SELECT TOP 1 '' AS Daily_Cost_Per_Person
FROM Data) ELSE Daily_Cost_Per_Person END), 1) AS Daily_Cost_Per_Person, CONVERT(VARCHAR, (CASE WHEN Acc_Exp IS NULL
THEN
(SELECT TOP 1 '' AS Acc_Exp
FROM Data) ELSE Acc_Exp END), 1) AS Acc_Exp
FROM Data
WHERE (Date_of_Entry BETWEEN @Date_of_Entry_From AND @Date_of_Entry_To) OR
(Date_of_Entry IS NULL)</CommandText>
<Parameters>
<Parameter AllowDbNull="True" AutogeneratedName="Date_of_Entry_From" ColumnName="CONVERT (CHAR(11), (CASE WHEN Date_of_Entry IS NULL THEN (SELECT TOP 1 '2/5/1981' AS Date_of_Entry FROM Data) ELSE Date_of_Entry END), 106)" DataSourceName="" DataTypeServer="datetime" DbType="DateTime" Direction="Input" ParameterName="@Date_of_Entry_From" Precision="0" Scale="0" Size="8" SourceColumn="Date_of_Entry" SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
<Parameter AllowDbNull="True" AutogeneratedName="Date_of_Entry_To" ColumnName="CONVERT (CHAR(11), (CASE WHEN Date_of_Entry IS NULL THEN (SELECT TOP 1 '2/5/1981' AS Date_of_Entry FROM Data) ELSE Date_of_Entry END), 106)" DataSourceName="" DataTypeServer="datetime" DbType="DateTime" Direction="Input" ParameterName="@Date_of_Entry_To" Precision="0" Scale="0" Size="8" SourceColumn="Date_of_Entry" SourceColumnNullMapping="False" SourceVersion="Current">
</Parameter>
</Parameters>
</DbCommand>
</SelectCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="Province" DataSetColumn="Province" />
<Mapping SourceColumn="District" DataSetColumn="District" />
<Mapping SourceColumn="Hospital" DataSetColumn="Hospital" />
<Mapping SourceColumn="Caterer_Name" DataSetColumn="Caterer_Name" />
<Mapping SourceColumn="Food_Item" DataSetColumn="Food_Item" />
<Mapping SourceColumn="Date_of_Entry" DataSetColumn="Date_of_Entry" />
<Mapping SourceColumn="Week" DataSetColumn="Week" />
<Mapping SourceColumn="No_of_Daigs" DataSetColumn="No_of_Daigs" />
<Mapping SourceColumn="No_of_Rotis" DataSetColumn="No_of_Rotis" />
<Mapping SourceColumn="No_of_Bene_Male" DataSetColumn="No_of_Bene_Male" />
<Mapping SourceColumn="No_of_Bene_Female" DataSetColumn="No_of_Bene_Female" />
<Mapping SourceColumn="Daily_Cost_Per_Person" DataSetColumn="Daily_Cost_Per_Person" />
<Mapping SourceColumn="Acc_Exp" DataSetColumn="Acc_Exp" />
<Mapping SourceColumn="Autokey" DataSetColumn="Autokey1" />
</Mappings>
<Sources>
</Sources>
</TableAdapter>
</Tables>
<Sources>
</Sources>
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="DataSet1" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="DataSet1" msprop:Generator_DataSetName="DataSet1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Data" msprop:Generator_UserTableName="Data" msprop:Generator_RowDeletedName="DataRowDeleted" msprop:Generator_RowChangedName="DataRowChanged" msprop:Generator_RowClassName="DataRow" msprop:Generator_RowChangingName="DataRowChanging" msprop:Generator_RowEvArgName="DataRowChangeEvent" msprop:Generator_RowEvHandlerName="DataRowChangeEventHandler" msprop:Generator_TableClassName="DataDataTable" msprop:Generator_TableVarName="tableData" msprop:Generator_RowDeletingName="DataRowDeleting" msprop:Generator_TablePropName="Data">
<xs:complexType>
<xs:sequence>
<xs:element name="Autokey" msdata:ReadOnly="true" msdata:AutoIncrement="true" msprop:Generator_UserColumnName="Autokey" msprop:Generator_ColumnVarNameInTable="columnAutokey" msprop:Generator_ColumnPropNameInRow="Autokey" msprop:Generator_ColumnPropNameInTable="AutokeyColumn" type="xs:int" />
<xs:element name="Province" msprop:Generator_UserColumnName="Province" msprop:Generator_ColumnVarNameInTable="columnProvince" msprop:Generator_ColumnPropNameInRow="Province" msprop:Generator_ColumnPropNameInTable="ProvinceColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="District" msprop:Generator_UserColumnName="District" msprop:Generator_ColumnVarNameInTable="columnDistrict" msprop:Generator_ColumnPropNameInRow="District" msprop:Generator_ColumnPropNameInTable="DistrictColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Hospital" msprop:Generator_UserColumnName="Hospital" msprop:Generator_ColumnVarNameInTable="columnHospital" msprop:Generator_ColumnPropNameInRow="Hospital" msprop:Generator_ColumnPropNameInTable="HospitalColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Caterer_Name" msprop:Generator_UserColumnName="Caterer_Name" msprop:Generator_ColumnVarNameInTable="columnCaterer_Name" msprop:Generator_ColumnPropNameInRow="Caterer_Name" msprop:Generator_ColumnPropNameInTable="Caterer_NameColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Food_Item" msprop:Generator_UserColumnName="Food_Item" msprop:Generator_ColumnVarNameInTable="columnFood_Item" msprop:Generator_ColumnPropNameInRow="Food_Item" msprop:Generator_ColumnPropNameInTable="Food_ItemColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Week" msprop:Generator_UserColumnName="Week" msprop:Generator_ColumnPropNameInRow="Week" msprop:Generator_ColumnVarNameInTable="columnWeek" msprop:Generator_ColumnPropNameInTable="WeekColumn" type="xs:string" minOccurs="0" />
<xs:element name="Date_of_Entry" msdata:ReadOnly="true" msprop:Generator_UserColumnName="Date_of_Entry" msprop:Generator_ColumnPropNameInRow="Date_of_Entry" msprop:Generator_ColumnVarNameInTable="columnDate_of_Entry" msprop:Generator_ColumnPropNameInTable="Date_of_EntryColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="11" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="No_of_Daigs" msdata:ReadOnly="true" msprop:Generator_UserColumnName="No_of_Daigs" msprop:Generator_ColumnPropNameInRow="No_of_Daigs" msprop:Generator_ColumnVarNameInTable="columnNo_of_Daigs" msprop:Generator_ColumnPropNameInTable="No_of_DaigsColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="No_of_Rotis" msdata:ReadOnly="true" msprop:Generator_UserColumnName="No_of_Rotis" msprop:Generator_ColumnPropNameInRow="No_of_Rotis" msprop:Generator_ColumnVarNameInTable="columnNo_of_Rotis" msprop:Generator_ColumnPropNameInTable="No_of_RotisColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="No_of_Bene_Male" msdata:ReadOnly="true" msprop:Generator_UserColumnName="No_of_Bene_Male" msprop:Generator_ColumnPropNameInRow="No_of_Bene_Male" msprop:Generator_ColumnVarNameInTable="columnNo_of_Bene_Male" msprop:Generator_ColumnPropNameInTable="No_of_Bene_MaleColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="No_of_Bene_Female" msdata:ReadOnly="true" msprop:Generator_UserColumnName="No_of_Bene_Female" msprop:Generator_ColumnPropNameInRow="No_of_Bene_Female" msprop:Generator_ColumnVarNameInTable="columnNo_of_Bene_Female" msprop:Generator_ColumnPropNameInTable="No_of_Bene_FemaleColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Daily_Cost_Per_Person" msdata:ReadOnly="true" msprop:Generator_UserColumnName="Daily_Cost_Per_Person" msprop:Generator_ColumnPropNameInRow="Daily_Cost_Per_Person" msprop:Generator_ColumnVarNameInTable="columnDaily_Cost_Per_Person" msprop:Generator_ColumnPropNameInTable="Daily_Cost_Per_PersonColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Acc_Exp" msdata:ReadOnly="true" msprop:Generator_UserColumnName="Acc_Exp" msprop:Generator_ColumnPropNameInRow="Acc_Exp" msprop:Generator_ColumnVarNameInTable="columnAcc_Exp" msprop:Generator_ColumnPropNameInTable="Acc_ExpColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Autokey1" msdata:ReadOnly="true" msdata:Caption="Autokey" msprop:Generator_UserColumnName="Autokey1" msprop:Generator_ColumnPropNameInRow="Autokey1" msprop:Generator_ColumnVarNameInTable="columnAutokey1" msprop:Generator_ColumnPropNameInTable="Autokey1Column" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
IIS slow on vista
http://forums.iis.net/t/1100987.aspx
conn str props: http://weblogs.asp.net/wallen/archive/2005/03/22/395496.aspx
add in conn str of web.config Min Pool Size=5
Formatting PDF from reportviewer (multiple page crossing problem)
use ratio calc
http://www.continuum2.com/js_ratio.php
In the Report Properties dialog if I set Page width to 8.27in and Page height to 11.69in then the Page Setup dialog of ReportViewer defaults to A4.
In the Report Properties dialog if I set Page width to 11.69in and Page height to 8.27in then the Page Setup dialog of ReportViewer defaults to A4, and Orientation defaults to Landscape.
--
customvalidator for date and tracing
put trace="true" in aspx top declaration
usually some other thing is altering the state during page load of the control to be validated. sometimes the field is being used as a filter and that effects other controls thru its sqldatasource.
Always keep sqldatasource of formview inside the formview
customvalidators problem with button firing
If VAL_FTR_Date_of_Entry_From.IsValid = True Then
use this kind of comparison on whatever control is accessing the control directly or indirectly thru for e.g an sqldatasource, and put this comparison usually on the button or the sub that is triggering the conflict command so that they run only after the validation is complete.
validation check for null values
make sure validateemptytext=true in custom validator
then do as normal
Dim TXT_Province As TextBox
TXT_Province = CType(FormView_Manage_Province.FindControl("ProvinceTextBox"), TextBox)
If TXT_Province.Text.Trim = "" Then
args.IsValid = False
Else
args.IsValid = True
End If
validating phone numbers, allowing only numbers and dashes
Use custom validator.
Protected Sub VAL_FV_Manage_Caterer_Name_Caterer_Telephone_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim ValidChars As String = "0123456789-,"
Dim RepChar As Char
'Dim sText As String = tmp_SupplierPhoneTextBox.Text
Dim sText As String
sText = CType(FormView_Manage_Caterer_Name.FindControl("Caterer_TelephoneTextBox"), TextBox).Text
Dim i As Integer
For i = 0 To sText.Length - 1 Step i + 1
RepChar = sText.Chars(i)
If ValidChars.IndexOf(RepChar) = -1 Then
args.IsValid = False
Return
End If
Next
args.IsValid = True
End Sub
Formview giving error when changing mode to insert : Violation of PRIMARY KEY constraint
if Violation of PRIMARY KEY constraint on changemode to insert do it on modechanged event of formview:
Protected Sub FormView_Manage_Province_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView_Manage_Province.ModeChanged
If FormView_Manage_Province.CurrentMode = FormViewMode.ReadOnly Then
FormView_Manage_Province.ChangeMode(FormViewMode.Insert)
End If
End Sub
page level error checking for update / delete / insert and general errors
put in main aspx.
Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
' BEGIN - catching errors due to referential integrity constraints
' getting the exception
Dim objErr As Exception = Server.GetLastError().GetBaseException()
Dim tempMsg As String
Dim tempStrAndErrCompDELETE As Boolean
Dim tempStrAndErrComp As Boolean
' getting the message from objerr (the real exception raised)
Dim tempErrorMessage As String
tempErrorMessage = objErr.Message.ToString()
' comparing variables for violations
tempStrAndErrCompDELETE = tempErrorMessage.Contains("DELETE")
tempStrAndErrComp = tempErrorMessage.Contains("")
' looking for DELETE violation
If (tempStrAndErrCompDELETE = True) Then
tempMsg = "This is a non-critical error. There was an error during DELETE operation. This was because the record you tried to delete is already being used. If a record is already being used in another table then deleting it would also delete its entry from there and that would create null references. For further explanation of this please contact Saad Hashmi, Asst. IT Programmer." _
+ vbCrLf + " Error: " + tempErrorMessage
Server.Transfer("TempErrorAdmin.aspx?request_tempMsg=" + tempMsg)
' looking for GENERAL violation
ElseIf (tempStrAndErrComp = True) Then
tempMsg = "This is a critical general error. For further explanation of this please contact Saad Hashmi, Asst. IT Programmer." _
+ " Error: " + tempErrorMessage
Server.Transfer("TempErrorAdmin.aspx?request_tempMsg=" + tempMsg)
End If
' clearing the server error raised
Server.ClearError()
End Sub
make a TempErrorAdmin.aspx page and place code...
Partial Class TempErrorAdmin
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tmp_lbl_ErrorLabel As Label
tmp_lbl_ErrorLabel = CType(FindControl("ErrorLabel"), Label)
tmp_lbl_ErrorLabel.Text = Request.QueryString("request_tempMsg")
End Sub
Protected Sub btn_back_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_back.Click
' If the querystring had a DELETE in it then transfer it back
' to requesting page on press of BACK BUTTON.
' However if querystring had something other than DELETE then transfer
' to default.aspx.
' This is because if querystring was something other than DELETE (or a ref. integrity violation)
' then the requesting page will transfer it back to error page since its a critical error.
Dim temp_PreviousPage As String
Dim tempStrAndErrCompDELETE As Boolean
Dim tempStrAndErrComp As Boolean
'Dim tmp_ContentPlaceHolder As ContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
Dim tmp_lbl_ErrorLabel As Label = CType(FindControl("ErrorLabel"), Label)
tmp_lbl_ErrorLabel.Text = Request.QueryString("request_tempMsg")
' comparing variables for violations
tempStrAndErrCompDELETE = tmp_lbl_ErrorLabel.Text.Contains("DELETE")
tempStrAndErrComp = tmp_lbl_ErrorLabel.Text.Contains("")
' looking for DELETE violation
If (tempStrAndErrCompDELETE = True) Then
temp_PreviousPage = Request.UrlReferrer.ToString
Response.Redirect(temp_PreviousPage)
' looking for GENERAL violation
ElseIf (tempStrAndErrComp = True) Then
temp_PreviousPage = "Default.aspx"
Response.Redirect(temp_PreviousPage)
End If
End Sub
End Class
adding new line in string or textbox
vbCrLf. or environment.NewLine or <br> ..use <br> inside the string.
e.g
tempMsg = "This is a non-critical error. There was an error during DELETE operation. This was because the record you tried to delete is already being used. If a record is already being used in another table then deleting it would also delete its entry from there and that would create null references. For further explanation of this please contact Saad Hashmi, Asst. IT Programmer." + Environment.NewLine + " Error: " + tempErrorMessage
e.g
tempMsg = "This is a non-critical error. There was an error during DELETE operation. This was because the record you tried to delete is already being used. If a record is already being used in another table then deleting it would also delete its entry from there and that would create null references. For further explanation of this please contact Saad Hashmi, Asst. IT Programmer." + vbCrLf + " Error: " + tempErrorMessage
changing linkbutton to button in GV and FV
just replace word linkbutton with button, make sure to do it in closing tag as well.
adding button in GV
<asp:CommandField ShowEditButton="True" ButtonType="Button" />
putting value buttontype
capturing key press enter to click a button
http://www.codeproject.com/KB/aspnet/EnterKeyToButtonClick.aspx
im implementing panel method
DefaultButton="btnSearch2"
im putting panel inside the editview of the FV for login.
changing selected value in dropdownlist in start
Protected Sub FormView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewModeEventArgs) Handles FormView1.ModeChanging
If FormView1.CurrentMode = FormViewMode.Edit Then
Dim tmp_DDL_Login As DropDownList = CType(FormView1.FindControl("DDL_Login"), DropDownList)
tmp_DDL_Login.Items.FindByValue(3).Selected = True
End If
End Sub
http://www.dotnet247.com/247reference/msgs/21/108986.aspx
make sure if the textbox was bound before to sqldatasource then remove bindings as well.
Gridview SORTING Int/float/money fields - sorting gridview in natural order (alphanumerically / asciibetically)
-convert any money or float or int or money type to int in a convert() statement in t-sql to remove any .00. trailing zeros
CONVERT(INT, [Daily_Cost_Per_Person], 1) AS Daily_Cost_Per_Person
-do same as above in DDL sqldatasource.
-convert in filterexpression any int/float/money to string
FilterExpression = "
(CONVERT(Daily_Cost_Per_Person,'System.String') LIKE '{0}')
"
-later on add zeros to the number in the GV and FV while its being rendered:
http://forums.asp.net/t/1114891.aspx
--other methods---
http://www.codeproject.com/KB/string/NaturalSortComparer.aspx
http://www.codinghorror.com/blog/2007/12/sorting-for-humans-natural-sort-order.html
http://tablesorter.com/docs/
--
Error during delete in gridview...Error "You have specified that your delete command compares all values on SqlDataSource"
Delete ConflictDetection="CompareAllValues" from sqldatasource
also...
Turn the col into an itemtemplate in gridview
make sure there is not Eval instead of Bind in EditItemtemplate
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:TemplateField HeaderText="Food_Item" SortExpression="Food_Item">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Food_Item") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Food_Item") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
--
Adding * in DDL as initial value
<asp:DropDownList ID="FTR_Province" runat="server"
DataSourceID="SqlDataSource1_Province" DataTextField="Province"
DataValueField="Province" AppendDataBoundItems="true" AutoPostBack="True">
<asp:ListItem Value="*">*</asp:ListItem>
Wednesday, October 20, 2010
Auto increment in GV and Reportviewer starting at 1
no need to add the primary key col cause it starts from 0.
In reportviewer add col based on PRIMARY KEY of the table which will create an auto increment col. For it to start at one open code of xsd file and add msdata:AutoIncrement="1 in
<xs:complexType>
<xs:sequence>
<xs:element name="Autokey" msdata:ReadOnly="true" msdata:AutoIncrement="1" msprop:Generator_UserColumnName="Autokey" msprop:Generator_ColumnVarNameInTable="columnAutokey" msprop:Generator_ColumnPropNameInRow="Autokey" msprop:Generator_ColumnPropNameInTable="AutokeyColumn" type="xs:int" />
<xs:element name="Province" msprop:Generator_UserColumnName="Province" msprop:Generator_ColumnVarNameInTable="columnProvince" msprop:Generator_ColumnPropNameInRow="Province" msprop:Generator_ColumnPropNameInTable="ProvinceColumn" minOccurs="0">
<xs:simpleType>
In gridview add a col in aspx
<asp:TemplateField HeaderText="S_No">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
--
Selecting NULLS in reportviewer individual textbox fields
=IIF(Fields!No_of_Daigs.Value = 0, Nothing, Fields!No_of_Daigs.Value)
schematic of database, handling nulls
This ensures for blanks, NULL values are stored in the db.
During select in sqldatasource or objectdatasource, it will select nulls in integer and date cols as 0 and 01 jan 1900 repectively. therefore in GV and FV we must individually set every textbox in row to blank or nothing or null if a 0 or 01 jan 1900 is found.
adding parameters in reportviewer
Failed to map the path '/'
Enable all sorts of permissions on the physical folders and subfolders of the website.
Choose old pool in IIIS manager virtual directory
Configuring reportviewer for filter
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="DataSet1TableAdapters.DataTableAdapter" FilterExpression = "(Province LIKE '{0}')" >
<FilterParameters>
<asp:controlparameter name="Province" controlid="FTR_Province"/>
</FilterParameters>
</asp:ObjectDataSource>
-----------
add ReportViewer1.LocalReport.Refresh() in page_load of the aspx
Refresh Gridview if not updated on press on select button
Select Distinct and NON NULL values from SQLDATASOURCE
--
use * in filter DDL to make sure erratic behavior in filtering records is not encountered
Tuesday, October 19, 2010
Choosing top row in DDL as NULL from SQLDATASOURCE
UNION ALL
SELECT DISTINCT Autokey
FROM Data
http://forums.asp.net/p/1561253/3864962.aspx
---------
however above method might not work in integer fields.
use http://imar.spaanjaars.com/281/how-do-i-add-an-additional-item-to-a-databound-dropdownlist-control-in-aspnet
In ASP.NET 2.0 and onwards things are much easier. The DropDownList control and other list controls now have a AppendDataBoundItems (7) property. With this property set to true, a call to DataBind leaves all existing items in the list. That allows you to add the extra items declaratively in the markup:
<asp:DropDownList ID="DropDownList1" runat="server"
AppendDataBoundItems="true">
<asp:ListItem Value="*">Please select a country</asp:ListItem>
</asp:DropDownList>
That's it. No more messing around with code in the code behind to add the item. Just set AppendDataBoundItems to true and the manually added item stays where it was.
Make sure there is a * in "value" above on listitem.
--------
The above method does not work in whole unless accompanied by converting to varchar of any int value fields in sqldatasource. I converted them all to varchar to be on safe side.
SelectCommand="SELECT CONVERT(VARCHAR, [Autokey], 1) AS 'Autokey', CONVERT(VARCHAR,[Province], 1) AS 'Province', CONVERT(VARCHAR, [District], 1) AS 'District', CONVERT(VARCHAR, [Hospital], 1) AS 'Hospital', CONVERT(VARCHAR, [Caterer_Name], 1) AS 'Caterer_Name', CONVERT(VARCHAR, [Date_of_Entry], 1) AS 'Date_of_Entry', CONVERT(VARCHAR, [No_of_Daigs], 1) AS 'No_of_Daigs', CONVERT(VARCHAR, [Food_Item], 1) AS 'Food_Item', CONVERT(VARCHAR, [No_of_Rotis], 1) AS 'No_of_Rotis', CONVERT(VARCHAR, [No_of_Bene_Male], 1) AS No_of_Bene_Male, CONVERT(VARCHAR, [No_of_Bene_Female], 1) AS No_of_Bene_Female, CONVERT(VARCHAR, [Daily_Cost_Per_Person], 1) AS Daily_Cost_Per_Person, CONVERT(VARCHAR, [Acc_Exp], 1) AS Acc_Exp FROM [Data]"
also make sure in select statement of sqldatasource of the individual dropdownlist, you use the t-sql as such in order to eliminate all possible nulls and get all distinct values
SELECT
CONVERT(VARCHAR, [Autokey], 1) AS 'Autokey',
CONVERT(VARCHAR, [Province], 1) AS 'Province',
CONVERT(VARCHAR, [District], 1) AS 'District',
CONVERT(VARCHAR, [Hospital], 1) AS 'Hospital',
CONVERT(VARCHAR,
(CASE
WHEN Caterer_Name IS NULL THEN
(SELECT TOP 1 '' AS Caterer_Name FROM Data)
ELSE Caterer_Name
END), 1) AS Caterer_Name,
CONVERT(VARCHAR, [Date_of_Entry], 1) AS 'Date_of_Entry',
CONVERT(VARCHAR, [No_of_Daigs], 1) AS 'No_of_Daigs',
CONVERT(VARCHAR, [Food_Item], 1) AS 'Food_Item',
CONVERT(VARCHAR, [No_of_Rotis], 1) AS 'No_of_Rotis',
CONVERT(VARCHAR, [No_of_Bene_Male], 1) AS No_of_Bene_Male,
CONVERT(VARCHAR, [No_of_Bene_Female], 1) AS No_of_Bene_Female,
CONVERT(VARCHAR, [Daily_Cost_Per_Person], 1) AS Daily_Cost_Per_Person,
CONVERT(VARCHAR, [Acc_Exp], 1) AS Acc_Exp
FROM [Data]
http://forums.asp.net/t/1250459.aspx
The key code here is
CONVERT(VARCHAR,
(CASE
WHEN Caterer_Name IS NULL THEN
(SELECT TOP 1 ' ' AS Caterer_Name FROM Data)
ELSE Caterer_Name
END), 1) AS Caterer_Name,
this converts int to string as well as selects null as a value
full example
SELECT
CONVERT(VARCHAR,
(CASE
WHEN Autokey IS NULL THEN
(SELECT TOP 1 '' AS Autokey FROM Data)
ELSE Autokey
END), 1) AS Autokey,
CONVERT(VARCHAR,
(CASE
WHEN Province IS NULL THEN
(SELECT TOP 1 '' AS Province FROM Data)
ELSE Province
END), 1) AS Province,
CONVERT(VARCHAR,
(CASE
WHEN District IS NULL THEN
(SELECT TOP 1 '' AS District FROM Data)
ELSE District
END), 1) AS District,
CONVERT(VARCHAR,
(CASE
WHEN Hospital IS NULL THEN
(SELECT TOP 1 '' AS Hospital FROM Data)
ELSE Hospital
END), 1) AS Hospital,
CONVERT(VARCHAR,
(CASE
WHEN Caterer_Name IS NULL THEN
(SELECT TOP 1 '' AS Caterer_Name FROM Data)
ELSE Caterer_Name
END), 1) AS Caterer_Name,
CONVERT(VARCHAR,
(CASE
WHEN Date_of_Entry IS NULL THEN
(SELECT TOP 1 '' AS Date_of_Entry FROM Data)
ELSE Date_of_Entry
END), 1) AS Date_of_Entry,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Daigs IS NULL THEN
(SELECT TOP 1 '' AS No_of_Daigs FROM Data)
ELSE No_of_Daigs
END), 1) AS No_of_Daigs,
CONVERT(VARCHAR,
(CASE
WHEN Food_Item IS NULL THEN
(SELECT TOP 1 '' AS Food_Item FROM Data)
ELSE Food_Item
END), 1) AS Food_Item,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Rotis IS NULL THEN
(SELECT TOP 1 '' AS No_of_Rotis FROM Data)
ELSE No_of_Rotis
END), 1) AS No_of_Rotis,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Bene_Male IS NULL THEN
(SELECT TOP 1 '' AS No_of_Bene_Male FROM Data)
ELSE No_of_Bene_Male
END), 1) AS No_of_Bene_Male,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Bene_Female IS NULL THEN
(SELECT TOP 1 '' AS No_of_Bene_Female FROM Data)
ELSE No_of_Bene_Female
END), 1) AS No_of_Bene_Female,
CONVERT(VARCHAR,
(CASE
WHEN Daily_Cost_Per_Person IS NULL THEN
(SELECT TOP 1 '' AS Daily_Cost_Per_Person FROM Data)
ELSE Daily_Cost_Per_Person
END), 1) AS Daily_Cost_Per_Person,
CONVERT(VARCHAR,
(CASE
WHEN Acc_Exp IS NULL THEN
(SELECT TOP 1 '' AS Acc_Exp FROM Data)
ELSE Acc_Exp
END), 1) AS Acc_Exp
FROM Data
--------------
Formview stuck on first record even when clicking edit button from gridview do:
Protected Sub BTN_GV_Details_Click(ByVal sender As Object, ByVal e As System.EventArgs)
FormView1.ChangeMode(FormViewMode.ReadOnly)
FormView1.ChangeMode(FormViewMode.Edit)
End Sub
basically change mode of formview to readonly and then to edit. make sure this is implemented on the select button of gridview NOT the edit button, so that selectcommand of sqldatasource is executed first.
also you need to make sure that commandname = "select" on both edit and select buttons of the gridview.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Autokey"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="GV_Edit_button" runat="server" CausesValidation="False"
OnClick="GV_Edit_button_Click" Text="Edit" CommandName="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="GV_Details_button" runat="server" Text="Details..."
onclick="GV_Details_button_Click" CommandName="Select"></asp:LinkButton>
</ItemTemplate>
-------------
if error such as 'FV_Edit_DDL_Caterer_Name' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
this means null value is not being found in the supporting table. no need to add a null row in the supporting table. what you need to do instead is put a - in the listitem of the dropdownlist in edititemtemplate and insertitemtemplate of the formview. the reason we are putting value "-" in our case is because we are taking - as null from the sqldatasource select statement. in normal instances you would take "" to select null value.
e.g
Caterer_Name: <asp:DropDownList ID="FV_Edit_DDL_Caterer_Name" runat="server" DataSourceID="SqlDataSource1_Caterer"
DataTextField="Caterer_Name" DataValueField="Caterer_Name" SelectedValue='<%# Bind("Caterer_Name") %>' AppendDataBoundItems="true">
<asp:ListItem Value="-"></asp:ListItem>
</asp:DropDownList>
------
set NULLDISPLAYTEXT property of the column in gridview to dash - to display dashes for nulls.
Convert date format to 1 jan 2000 style in sqldatasource
difference between filterexpression and selectexpression
As you probably can guess, filtering on the database side is much more efficient than bringing back all data to the data source control and then having it filter the results. However, there are times when would want to use the FilterExpression and FilterParameters properties - in fact, both techniques can be used in tandem. For our examples now, stick with the parameterized queries and SelectParameters and just remember that the SelectParameters specify the parameter values that are sent in the database's SELECT query whereas the FilterParameters are those parameters used to filter the data returned from the database (and would only be set if there was a FilterExpression value defined).
http://www.4guysfromrolla.com/demos/printPage.aspx?path=/articles/030106-1.aspx
--
Setting Gridview labels to NULL
REM Assigning EMPTY values to integer and datetime labels in GV
REM Note that it will not involve any text fields
REM Taking total rows in GV
Dim tmp_Total_GV_Rows As String = GridView1.Rows.Count
REM Recursively going through each GV row, last recursion inside will be at 0 therefore > 0 is necessary
While tmp_Total_GV_Rows > 0
REM Decreasing value of row holder to cover all rows, must be on top to start indexing appropriately since it goes from 0 onwards.
tmp_Total_GV_Rows = tmp_Total_GV_Rows - 1
REM --Integer Field GV_LBL_Date_of_Entry--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text() = "01 Jan 1900" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Daigs--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(6).FindControl("GV_LBL_No_of_Daigs"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(6).FindControl("GV_LBL_No_of_Daigs"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Rotis--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(7).FindControl("GV_LBL_No_of_Rotis"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(7).FindControl("GV_LBL_No_of_Rotis"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Bene_Male--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(8).FindControl("GV_LBL_No_of_Bene_Male"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(8).FindControl("GV_LBL_No_of_Bene_Male"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Bene_Female--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(9).FindControl("GV_LBL_No_of_Bene_Female"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(9).FindControl("GV_LBL_No_of_Bene_Female"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_Daily_Cost_Per_Person--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = "0.00" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_Acc_Exp--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(11).FindControl("GV_LBL_Acc_Exp"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(11).FindControl("GV_LBL_Acc_Exp"), Label).Text() = ""
End If
End While
End Sub
Selecting dates based on to and from dates from filter
FROM Data
WHERE Date_of_Entry BETWEEN @Date_of_Entry_From AND @Date_of_Entry_To
full listing:
SelectCommand="
SELECT
CONVERT(VARCHAR,
(CASE
WHEN Autokey IS NULL THEN
(SELECT TOP 1 '' AS Autokey FROM Data)
ELSE Autokey
END), 1) AS Autokey,
CONVERT(VARCHAR,
(CASE
WHEN Province IS NULL THEN
(SELECT TOP 1 '' AS Province FROM Data)
ELSE Province
END), 1) AS Province,
CONVERT(VARCHAR,
(CASE
WHEN District IS NULL THEN
(SELECT TOP 1 '' AS District FROM Data)
ELSE District
END), 1) AS District,
CONVERT(VARCHAR,
(CASE
WHEN Hospital IS NULL THEN
(SELECT TOP 1 '' AS Hospital FROM Data)
ELSE Hospital
END), 1) AS Hospital,
CONVERT(VARCHAR,
(CASE
WHEN Caterer_Name IS NULL THEN
(SELECT TOP 1 '' AS Caterer_Name FROM Data)
ELSE Caterer_Name
END), 1) AS Caterer_Name,
CONVERT(CHAR(11),
(CASE
WHEN Date_of_Entry IS NULL THEN
(SELECT TOP 1 '' AS Date_of_Entry FROM Data)
ELSE Date_of_Entry
END), 106) AS Date_of_Entry,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Daigs IS NULL THEN
(SELECT TOP 1 '' AS No_of_Daigs FROM Data)
ELSE No_of_Daigs
END), 1) AS No_of_Daigs,
CONVERT(VARCHAR,
(CASE
WHEN Food_Item IS NULL THEN
(SELECT TOP 1 '' AS Food_Item FROM Data)
ELSE Food_Item
END), 1) AS Food_Item,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Rotis IS NULL THEN
(SELECT TOP 1 '' AS No_of_Rotis FROM Data)
ELSE No_of_Rotis
END), 1) AS No_of_Rotis,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Bene_Male IS NULL THEN
(SELECT TOP 1 '' AS No_of_Bene_Male FROM Data)
ELSE No_of_Bene_Male
END), 1) AS No_of_Bene_Male,
CONVERT(VARCHAR,
(CASE
WHEN No_of_Bene_Female IS NULL THEN
(SELECT TOP 1 '' AS No_of_Bene_Female FROM Data)
ELSE No_of_Bene_Female
END), 1) AS No_of_Bene_Female,
CONVERT(VARCHAR,
(CASE
WHEN Daily_Cost_Per_Person IS NULL THEN
(SELECT TOP 1 '' AS Daily_Cost_Per_Person FROM Data)
ELSE Daily_Cost_Per_Person
END), 1) AS Daily_Cost_Per_Person,
CONVERT(VARCHAR,
(CASE
WHEN Acc_Exp IS NULL THEN
(SELECT TOP 1 '' AS Acc_Exp FROM Data)
ELSE Acc_Exp
END), 1) AS Acc_Exp
FROM Data
WHERE Date_of_Entry BETWEEN @Date_of_Entry_From AND @Date_of_Entry_To
"
then add
<SelectParameters>
<asp:ControlParameter Name="Date_of_Entry_From" ControlID="FTR_Date_of_Entry_From" />
<asp:ControlParameter Name="Date_of_Entry_To" ControlID="FTR_Date_of_Entry_To" />
</SelectParameters>
Format currency in reportviewer, Gridview and Formview
REM -- Currency Field Daily_Cost_Per_PersonLabel
Dim tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel As Label
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel = CType(FormView1.FindControl("Daily_Cost_Per_PersonLabel"), Label)
Dim str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel As String = tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text
If str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel = "0.00" Then
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text = ""
Else
REM Putting Rs. Currency Symbol in front of FV row text
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text = "Rs. " + tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text
End If
Full text:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
'FormView1.ChangeMode(FormViewMode.Edit)
' If FormView1.Visible = True Then
' FormView1.Visible = True
REM Setting Integer and Date textfields in Item view of Formview to BLANK
REM In Readonly Mode
If FormView1.CurrentMode = FormViewMode.ReadOnly Then
REM -- DateTime Field Date_of_EntryLabel
Dim tmp_FV_Item__Temp_Date_of_EntryLabel As Label
tmp_FV_Item__Temp_Date_of_EntryLabel = CType(FormView1.FindControl("Date_of_EntryLabel"), Label)
Dim str_tmp_FV_Item__Temp_Date_of_EntryLabel As String = tmp_FV_Item__Temp_Date_of_EntryLabel.Text
If str_tmp_FV_Item__Temp_Date_of_EntryLabel = "01 Jan 1900" Then
tmp_FV_Item__Temp_Date_of_EntryLabel.Text = ""
End If
REM -- Integer Field No_of_DaigsLabel
Dim tmp_FV_Item__Temp_No_of_DaigsLabel As Label
tmp_FV_Item__Temp_No_of_DaigsLabel = CType(FormView1.FindControl("No_of_DaigsLabel"), Label)
Dim str_tmp_FV_Item__Temp_No_of_DaigsLabel As String = tmp_FV_Item__Temp_No_of_DaigsLabel.Text
If str_tmp_FV_Item__Temp_No_of_DaigsLabel = "0" Then
tmp_FV_Item__Temp_No_of_DaigsLabel.Text = ""
End If
REM -- Integer Field No_of_RotisLabel
Dim tmp_FV_Item__Temp_No_of_RotisLabel As Label
tmp_FV_Item__Temp_No_of_RotisLabel = CType(FormView1.FindControl("No_of_RotisLabel"), Label)
Dim str_tmp_FV_Item__Temp_No_of_RotisLabel As String = tmp_FV_Item__Temp_No_of_RotisLabel.Text
If str_tmp_FV_Item__Temp_No_of_RotisLabel = "0" Then
tmp_FV_Item__Temp_No_of_RotisLabel.Text = ""
End If
REM -- Integer Field No_of_Bene_MaleLabel
Dim tmp_FV_Item__Temp_No_of_Bene_MaleLabel As Label
tmp_FV_Item__Temp_No_of_Bene_MaleLabel = CType(FormView1.FindControl("No_of_Bene_MaleLabel"), Label)
Dim str_tmp_FV_Item__Temp_No_of_Bene_MaleLabel As String = tmp_FV_Item__Temp_No_of_Bene_MaleLabel.Text
If str_tmp_FV_Item__Temp_No_of_Bene_MaleLabel = "0" Then
tmp_FV_Item__Temp_No_of_Bene_MaleLabel.Text = ""
End If
REM -- Integer Field No_of_Bene_FemaleLabel
Dim tmp_FV_Item__Temp_No_of_Bene_FemaleLabel As Label
tmp_FV_Item__Temp_No_of_Bene_FemaleLabel = CType(FormView1.FindControl("No_of_Bene_FemaleLabel"), Label)
Dim str_tmp_FV_Item__Temp_No_of_Bene_FemaleLabel As String = tmp_FV_Item__Temp_No_of_Bene_FemaleLabel.Text
If str_tmp_FV_Item__Temp_No_of_Bene_FemaleLabel = "0" Then
tmp_FV_Item__Temp_No_of_Bene_FemaleLabel.Text = ""
End If
REM -- Currency Field Daily_Cost_Per_PersonLabel
Dim tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel As Label
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel = CType(FormView1.FindControl("Daily_Cost_Per_PersonLabel"), Label)
Dim str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel As String = tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text
If str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel = "0.00" Then
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text = ""
Else
REM Putting Rs. Currency Symbol in front of FV row text
tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text = "Rs. " + tmp_FV_Item__Temp_Daily_Cost_Per_PersonLabel.Text
End If
REM -- Integer Field Acc_ExpLabel
Dim tmp_FV_Item__Temp_Acc_ExpLabel As Label
tmp_FV_Item__Temp_Acc_ExpLabel = CType(FormView1.FindControl("Acc_ExpLabel"), Label)
Dim str_tmp_FV_Item__Temp_Acc_ExpLabel As String = tmp_FV_Item__Temp_Acc_ExpLabel.Text
If str_tmp_FV_Item__Temp_Acc_ExpLabel = "0" Then
tmp_FV_Item__Temp_Acc_ExpLabel.Text = ""
End If
End If
REM In Insert Mode
If FormView1.CurrentMode = FormViewMode.Insert Then
REM -- DateTime Field Date_of_EntryText
Dim tmp_FV_Item__Temp_Date_of_EntryText As TextBox
tmp_FV_Item__Temp_Date_of_EntryText = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Date_of_EntryText As String = tmp_FV_Item__Temp_Date_of_EntryText.Text
If str_tmp_FV_Item__Temp_Date_of_EntryText = "01 Jan 1900" Then
tmp_FV_Item__Temp_Date_of_EntryText.Text = ""
End If
REM -- Integer Field No_of_DaigsText
Dim tmp_FV_Item__Temp_No_of_DaigsText As TextBox
tmp_FV_Item__Temp_No_of_DaigsText = CType(FormView1.FindControl("No_of_DaigsTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_DaigsText As String = tmp_FV_Item__Temp_No_of_DaigsText.Text
If str_tmp_FV_Item__Temp_No_of_DaigsText = "0" Then
tmp_FV_Item__Temp_No_of_DaigsText.Text = ""
End If
REM -- Integer Field No_of_RotisText
Dim tmp_FV_Item__Temp_No_of_RotisText As TextBox
tmp_FV_Item__Temp_No_of_RotisText = CType(FormView1.FindControl("No_of_RotisTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_RotisText As String = tmp_FV_Item__Temp_No_of_RotisText.Text
If str_tmp_FV_Item__Temp_No_of_RotisText = "0" Then
tmp_FV_Item__Temp_No_of_RotisText.Text = ""
End If
REM -- Integer Field No_of_Bene_MaleText
Dim tmp_FV_Item__Temp_No_of_Bene_MaleText As TextBox
tmp_FV_Item__Temp_No_of_Bene_MaleText = CType(FormView1.FindControl("No_of_Bene_MaleTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_Bene_MaleText As String = tmp_FV_Item__Temp_No_of_Bene_MaleText.Text
If str_tmp_FV_Item__Temp_No_of_Bene_MaleText = "0" Then
tmp_FV_Item__Temp_No_of_Bene_MaleText.Text = ""
End If
REM -- Integer Field No_of_Bene_FemaleText
Dim tmp_FV_Item__Temp_No_of_Bene_FemaleText As TextBox
tmp_FV_Item__Temp_No_of_Bene_FemaleText = CType(FormView1.FindControl("No_of_Bene_FemaleTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_Bene_FemaleText As String = tmp_FV_Item__Temp_No_of_Bene_FemaleText.Text
If str_tmp_FV_Item__Temp_No_of_Bene_FemaleText = "0" Then
tmp_FV_Item__Temp_No_of_Bene_FemaleText.Text = ""
End If
REM -- Currency Field Daily_Cost_Per_PersonText
Dim tmp_FV_Item__Temp_Daily_Cost_Per_PersonText As TextBox
tmp_FV_Item__Temp_Daily_Cost_Per_PersonText = CType(FormView1.FindControl("Daily_Cost_Per_PersonTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonText As String = tmp_FV_Item__Temp_Daily_Cost_Per_PersonText.Text
If str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonText = "0.00" Then
tmp_FV_Item__Temp_Daily_Cost_Per_PersonText.Text = ""
End If
REM -- Integer Field Acc_ExpText
Dim tmp_FV_Item__Temp_Acc_ExpText As TextBox
tmp_FV_Item__Temp_Acc_ExpText = CType(FormView1.FindControl("Acc_ExpTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Acc_ExpText As String = tmp_FV_Item__Temp_Acc_ExpText.Text
If str_tmp_FV_Item__Temp_Acc_ExpText = "0" Then
tmp_FV_Item__Temp_Acc_ExpText.Text = ""
End If
End If
REM In Edit Mode setting integer and datetime fields to blank
If FormView1.Visible = True And FormView1.CurrentMode = FormViewMode.Edit Then
REM -- DateTime Field Date_of_EntryText
Dim tmp_FV_Item__Temp_Date_of_EntryText As TextBox
tmp_FV_Item__Temp_Date_of_EntryText = CType(FormView1.FindControl("Date_of_EntryTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Date_of_EntryText As String = tmp_FV_Item__Temp_Date_of_EntryText.Text
If str_tmp_FV_Item__Temp_Date_of_EntryText = "01 Jan 1900" Then
tmp_FV_Item__Temp_Date_of_EntryText.Text = ""
End If
REM -- Integer Field No_of_DaigsText
Dim tmp_FV_Item__Temp_No_of_DaigsText As TextBox
tmp_FV_Item__Temp_No_of_DaigsText = CType(FormView1.FindControl("No_of_DaigsTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_DaigsText As String = tmp_FV_Item__Temp_No_of_DaigsText.Text
If str_tmp_FV_Item__Temp_No_of_DaigsText = "0" Then
tmp_FV_Item__Temp_No_of_DaigsText.Text = ""
End If
REM -- Integer Field No_of_RotisText
Dim tmp_FV_Item__Temp_No_of_RotisText As TextBox
tmp_FV_Item__Temp_No_of_RotisText = CType(FormView1.FindControl("No_of_RotisTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_RotisText As String = tmp_FV_Item__Temp_No_of_RotisText.Text
If str_tmp_FV_Item__Temp_No_of_RotisText = "0" Then
tmp_FV_Item__Temp_No_of_RotisText.Text = ""
End If
REM -- Integer Field No_of_Bene_MaleText
Dim tmp_FV_Item__Temp_No_of_Bene_MaleText As TextBox
tmp_FV_Item__Temp_No_of_Bene_MaleText = CType(FormView1.FindControl("No_of_Bene_MaleTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_Bene_MaleText As String = tmp_FV_Item__Temp_No_of_Bene_MaleText.Text
If str_tmp_FV_Item__Temp_No_of_Bene_MaleText = "0" Then
tmp_FV_Item__Temp_No_of_Bene_MaleText.Text = ""
End If
REM -- Integer Field No_of_Bene_FemaleText
Dim tmp_FV_Item__Temp_No_of_Bene_FemaleText As TextBox
tmp_FV_Item__Temp_No_of_Bene_FemaleText = CType(FormView1.FindControl("No_of_Bene_FemaleTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_No_of_Bene_FemaleText As String = tmp_FV_Item__Temp_No_of_Bene_FemaleText.Text
If str_tmp_FV_Item__Temp_No_of_Bene_FemaleText = "0" Then
tmp_FV_Item__Temp_No_of_Bene_FemaleText.Text = ""
End If
REM -- Currency Field Daily_Cost_Per_PersonText
Dim tmp_FV_Item__Temp_Daily_Cost_Per_PersonText As TextBox
tmp_FV_Item__Temp_Daily_Cost_Per_PersonText = CType(FormView1.FindControl("Daily_Cost_Per_PersonTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonText As String = tmp_FV_Item__Temp_Daily_Cost_Per_PersonText.Text
If str_tmp_FV_Item__Temp_Daily_Cost_Per_PersonText = "0.00" Then
tmp_FV_Item__Temp_Daily_Cost_Per_PersonText.Text = ""
End If
REM -- Integer Field Acc_ExpText
Dim tmp_FV_Item__Temp_Acc_ExpText As TextBox
tmp_FV_Item__Temp_Acc_ExpText = CType(FormView1.FindControl("Acc_ExpTextBox"), TextBox)
Dim str_tmp_FV_Item__Temp_Acc_ExpText As String = tmp_FV_Item__Temp_Acc_ExpText.Text
If str_tmp_FV_Item__Temp_Acc_ExpText = "0" Then
tmp_FV_Item__Temp_Acc_ExpText.Text = ""
End If
End If
'End If
End Sub
--- Gridview---
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = "0.00" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = ""
Else
REM Putting Rs. Currency Symbol in front of the row text
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = "Rs. " + CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text()
FUll listing:
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
REM Assigning EMPTY values to integer and datetime labels in GV
REM Note that it will not involve any text fields
REM Taking total rows in GV
Dim tmp_Total_GV_Rows As String = GridView1.Rows.Count
REM Recursively going through each GV row, last recursion inside will be at 0 therefore > 0 is necessary
While tmp_Total_GV_Rows > 0
REM Decreasing value of row holder to cover all rows, must be on top to start indexing appropriately since it goes from 0 onwards.
tmp_Total_GV_Rows = tmp_Total_GV_Rows - 1
'CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text() = CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text.ToString("dd MMM yyyy, ddd")
REM --DateTime Field GV_LBL_Date_of_Entry--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text() = "01 Jan 1900" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(5).FindControl("GV_LBL_Date_of_Entry"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Daigs--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(6).FindControl("GV_LBL_No_of_Daigs"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(6).FindControl("GV_LBL_No_of_Daigs"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Rotis--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(7).FindControl("GV_LBL_No_of_Rotis"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(7).FindControl("GV_LBL_No_of_Rotis"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Bene_Male--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(8).FindControl("GV_LBL_No_of_Bene_Male"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(8).FindControl("GV_LBL_No_of_Bene_Male"), Label).Text() = ""
End If
REM --Integer Field GV_LBL_No_of_Bene_Female--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(9).FindControl("GV_LBL_No_of_Bene_Female"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(9).FindControl("GV_LBL_No_of_Bene_Female"), Label).Text() = ""
End If
REM --Currency Field GV_LBL_Daily_Cost_Per_Person--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = "0.00" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = ""
Else
REM Putting Rs. Currency Symbol in front of the row text
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text() = "Rs. " + CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(10).FindControl("GV_LBL_Daily_Cost_Per_Person"), Label).Text()
End If
REM --Integer Field GV_LBL_Acc_Exp--
REM Seeing if the item contains the value in question
If CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(11).FindControl("GV_LBL_Acc_Exp"), Label).Text() = "0" Then
REM Changing the value in question
CType(GridView1.Rows(tmp_Total_GV_Rows).Cells(11).FindControl("GV_LBL_Acc_Exp"), Label).Text() = ""
End If
End While
End Sub
--- Reportviewer ---
=Format(Fields!Daily_Cost_Per_Person.Value, "Rs.00")
Common VB functions are applied.
For some reason the integer is not to be denoted by anything, only the zeros are dot. It works.