Is there any possible way to change Gridview CellStyle while printing XtraReports?
Some approach from Winforms;
Protected Sub dg_listeOzet_RowCellStyle(sender As Object, e As RowCellStyleEventArgs) Handles gv_listeOzet.RowCellStyle
e.Appearance.BackColor = Color.LightBlue
End Sub
I found a solution referring this problem.
As you know, when you create XtraReports in winforms, it is created with two codefiles which are desing file and code file.
you can copy all of codes from desing class and code class from the WinForm project and paste them into a new class created in a ASP.NET project.
This enables you to catch
Private Sub gv_ListeOzetCritical_RowCellStyle(sender As Object, e As RowCellStyleEventArgs) Handles gv_ListeOzetCritical.RowCellStyle, gv_listeOzet.RowCellStyle
this event in the code file. when you full the gridview, this code event works and colour cells whichever you want.
Related
Well,I am beginner in Vb.NET although I had started learning few years back then took break again started and again break. So,anyways I am still the beginner and I am unable to understand what this WithEvents actually does and how and when to be used?I was studying on Dim and came across Dim WithEvents. I tried finding articles but all of them got bit higher level programming code compared to my level so it's gonna take time for me to reach that level.Until then for now I want to know WithEvents actual usage. Can someone give me any simple program that can be the clarity of WithEvents?
Source Links :
Generic WithEvents
VB.NET: WithEvents not Working
Strange WithEvents thing
WithEvents+Handles+Overrides
in vb.net how do I declare a public variable from a private sub
https://msdn.microsoft.com/en-us/library/stf7ebaz(v=vs.90).aspx
Thank you.
In short, WithEvents tells VB that the object you are declaring can raise events and that you intend to handle those events. This keyword goes hand in hand with the Handles keyword.
Create a new form and then add a button to it. Then double-click the button. VB will generate code similar to the following (notice the Handles keyword):
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
What you don't immediately see is the declaration for the button. If you look into the Form1.Designer.vb file you will see a line like this:
Friend WithEvents Button1 As System.Windows.Forms.Button
Notice the WithEvents. Since the button will raise events, the variable must be declared using that keyword.
I am new to VB and am working on an asp.net VB web application.
I have a partial class called s_new.aspx.vb which is the vb page behind the page s_new.aspx.
In this page there are a series of select dropdowns, which when selected lead to different options becoming available eg different select boxes appearing and or with different options.
One particular select box accesses a method in a different class (webcontrols).
My problem is that I need the web controls class to change its behavior based on a certain selection made in the s_new.aspx.vb page.
If I was using C# I would create a global variable and use that as a decision maker, but I cant seem to to this in VB.
below is a snippet of the code I am using:
Partial Class s_new
Protected Sub fldSourceofFunds_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles fldSourceofFunds.SelectedIndexChanged
Select Case fldSourceofFunds.SelectedIndex
Case 1
####
Case 2
###
Case 3
do something and set the variable
End Select
End Sub
Partial Class Webcontrols
Private Sub ReloadChildren()
If (variable from s_new has certain value) Then
ResetChildren()
Select Case PaymentMethodValue.ToLower.Trim
Case "payment via provider/platform"
Case "payment direct from client"
Case "payment via provider/platform and payment direct from client"
End Select
End if
End Sub
End Class
This is an existing project and I need to minimize the changes I make to the project, eg I am not able to make large changes to the structure to accommodate this change. As I said above, this would be a simple solution in C# and I assume it is simple here to.
How can create a unit test for the the Page_Load function in ASP.net?
I am using build in Visual Studio Unit test frame work. I want to create a unit test that check the Elements of the web page and their values.
I know about selenium and its abilities in unit testing.
This is the web Page to test WebPageControl.ascx.vb:
Public Class WebPageControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox.Visible = False
End Sub
End Class
This is the Unit test WebPageControlTest.vb:
Public Class WebPageControlTest
Public Sub PageLoadTest()
Dim target As WebPageControl_Accessor = New WebPageControl_Accessor()
Assert.IsFAlse(target.TextBox.Visible)
End Sub
End Class
After I do this I still get an error
Test method RechargeTest.WebPageControlTest.PageLoadTest threw exception: System.NullReferenceException: Object reference not set to an instance of an object.
You're probably not going to be able to new up a Page outside of the ASP.NET runtime.
You may want to google around for the MVP (Model-View-Presenter) pattern under ASP.NET. It makes testing web code a lot easier IMHO. This article is a good starting point:
http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx
If you want testable ASP.NET WebForms code, check out this project.
http://webformsmvp.com/
Web forms really wasn't built to be run through unit testing. Here's a good article on what I'm talking about. If you really want your pages to be testable I'd consider moving over to asp.net mvc or mvp.
I have a dropdown list that contains a collection of names. My entire names list is very large (over 2,000) so I would like to pair down the names in the drop down list to those starting with the same letter.
To do this I would like to have 26 links all on the same line, one for each letter in the alphabet ..
A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
The idea being that the user clicks on the letter they are interested in and the stored procedure that obtains the list of names is re-executed to only grab those names starting with the letter that was clicked and then the resulting dataset is rebound to the dropdown list.
What is vexing me is how to handle creating all the "Click Events" necessary to deal with the user "clicking" on a link. I could create 26 different event handlers, one for each link, but I have to believe there is a simpler way I am not seeing.
Form demonstration here is the click event for one link, the letter "A" ...
Protected Sub lnkLetterA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkLeterA.Click
Call LoadNamesIntoDropDown("A")
End Sub
Is there a way to create one event handler that could handle all 26 links? Thank you.
P.S. C# or VB.NET examples are fine. I just happen to be using VB.NET in this case.
You can reuse the same click handler a simple example
protected void HandleLinkClick(object sender, EventArgs e)
{
HyperLink link = (HyperLink)sender;
LoadNamesIntoDropDown(link.Text);
}
However, there are loads of autocomplete style solutions you can use. A free one from MS
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete.aspx
Of course you can have one handler to rule them all. Just connect the Click event of all the links to the same method.
Do you create the links dynamically in code-behind, or have you created them in the designer? If it is done in the designer:
Select a link
In the property grid, switch to the event view
In the click event, select your event handler from the dropdown list
Repeat for all links
In the event handler, use the sender argument to examine which of the links that was clicked, and act accordingly.
As per your example use:
Protected Sub lnkLetter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkLeterA.Click, lnkLeterB.Click, lnkLeterC.Click //etc
Call LoadNamesIntoDropDown(CType(sender, LinkLabel).Text)
End Sub
I have some common code that I would like to share between pages and I have been messing around with App_Code classes which is great but I would also like to use code that affects drop down lists example:
Sub Set_FirmType(ByVal Sender As Object, ByVal E As EventArgs)
subcategories.Visible = "false"
supplycategories.Visible = "false"
supplytypes.Visible = "false"
CityData.Visible="True"
CityDropDown.Visible="False"
CityDropDown.Items.Clear()
If DropFirmType.SelectedValue = "funeralhomes||FH" Then
CountryDropDown.ClearSelection()
CountryDropDown.Items.FindByValue("United States").Selected = True
CountryDropDown.Enabled = False
StateDropDown.Enabled = True
getStateDropDown("1")
End If
End Sub
Is their a way to put this in my App_Code class?
Thanks in advance!
It sounds like you have a sub-routine that is toggling visibility on multiple controls and setting some properties on a drop down list. You may want to consider packaging all of the controls into a single user control (.ascx) and putting the sub-routine in the code behind.
Housing the user control in the App_Code folder is not necessary for reuse across the application. Just drop the user control onto pages where you want the functionality.