VS2008里的ToStringwin2008 r2是什么意思思

Using Button columns in GridView Tutorial in Category ASP.NET
Using Button columns in GridView
Waqas Anwar
GridView control is one of the most powerful controls in ASP.NET 2.0. This control displays database records in typical tabular form, and provides features such as Sorting, Paging, Selection and Editing without writing a single line of code. It also has many different types of fields (columns) such as hyperlinks, images, checkboxes etc.
In the following tutorial, I will show you different techniques you can use to display&command buttons&in GridView.& For this tutorial I am using Microsoft famous sample database Northwind. I am displaying Products table in the GridView. Also make sure you are setting GridView DataKeyFields property to the Primary Key column of the Product Table such as ProductID. GridView control RowCommand event&will give you the ProductID of the product from the GridView Rows when user will click any of the button in the GridView. Here is the code of GridView control. &asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" && BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px" && CellPadding="4" DataKeyNames="ProductID"&& DataSourceID="SqlDataSource1" ForeColor="#333333"&&&&&&&&&&&&&&&&&&& &Columns&&&&&& &asp:BoundField DataField="ProductID"& HeaderText="ProductID" &&&&&&&& SortExpression="ProductID" /&&&&&& &asp:ButtonField ButtonType="link" CommandName="ProductName"&&&&&&&&& DataTextField="ProductName" HeaderText="Name" &&&&&&&& SortExpression="ProductName" /&&&&&& &asp:ButtonField ButtonType="button" CommandName="MoreDetail"&&&&&&&&& HeaderText="More Details" Text="More Details" /&&&&&& &asp:ButtonField ButtonType="Link" CommandName="ViewCategory"&&&&&&&&& HeaderText="View Category" Text="View Category" /&&&&&& &asp:ButtonField ButtonType="Image" CommandName="BuyNow"&&&&&&&&& HeaderText="Buy Now" ImageUrl="buynow.gif" /&&&&&& &asp:ButtonField DataTextField="UnitsInStock" HeaderText="Stock"&&&&&&&&& ButtonType="button" DataTextFormatString="{0} Items" &&&&&&&& CommandName="Stock" /&&&&&&&&&&&&&&&&&&&&&&&&&&& &/Columns&&&&&&&&&&&&&&&& &/asp:GridView&
To handle click event of the buttons in GridView you need to handle RowCommand event of the GridView control. Following code will show you how you can get RowIndex, ProductID and CommandName of the button when user click any button in the GridView.
Protected Sub GridView1_RowCommand(ByVal sender As Object, && ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) && Handles GridView1.RowCommand&& && Dim currentCommand As String = <mandName&& Dim currentRowIndex As Integer = Int32.Parse(<mandArgument.ToString())&& Dim ProductID As String = GridView1.DataKeys(currentRowIndex).Value
&& && && Label1.Text = "Command: " & currentCommand&& Label2.Text = "Row Index: " & currentRowIndex.ToString&& Label3.Text = "Product ID: " & ProductID End Sub
protected void GridView1_RowCommand(object sender, && System.Web.UI.WebControls.GridViewCommandEventArgs e) { &&& && string currentCommand = <mandName; && int currentRowIndex = Int32.Parse(<mandArgument.ToString());&&& string ProductID = GridView1.DataKeys[currentRowIndex].Value; &&& && Label1.Text = "Command: " + currentC && Label2.Text = "Row Index: " + currentRowIndex.ToS && Label3.Text = "Product ID: " + ProductID; &&& }
Blog Postsnew HoverPopover({
el: $adExplanation,
placement: 'bottom',
html: true,
content: content
});&We're trying Google Ads to subsidize server costs. If you are logged in, you won't see ads. Hover to learn more.&Academia.edu is experimenting with adsprogramming_asp.net_ajax475 PagesRun Opu&&connect to downloadGet&pdfREAD PAPERprogramming_asp.net_ajax
Log In&with&FacebookLog In&with&GoogleEmail:Password:Remember me on this computeror&Enter the email address you signed up with and we'll email you a reset link.
Academia & 2016c# - Can I automatically increment the file build version when using Visual Studio? - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).
If I look up the properties of say C:\Windows\notepad.exe, the Version tab gives "File version: 5.1.". I would like to get these cool numbers in the version of my dll's too, not version 1.0.0.0, which let's face it is a bit dull.
I tried a few things, but it doesn't seem to be out-of-box functionality, or maybe I'm just looking in the wrong place (as usual).
I work with mainly web projects....
I looked at both:
and I couldn't believe it so much effort to do something is standard practice.
It does not work in VS2005 as far I can tell (/KB/dotnet/AutoIncrementVersion.aspx)
35.5k1179103
11.7k175879
In visual Studio 2008, the following works.
Find the AssemblyInfo.cs file and find these 2 lines:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
You could try changing this to:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
But this won't give you the desired result, you will end up with a Product Version of 1.0.* and a File Version of 1.0.0.0. Not what you want!
However, if you remove the second of these lines and just have:
[assembly: AssemblyVersion("1.0.*")]
Then the compiler will set the File Version to be equal to the Product Version and you will get your desired result of an automatically increment product and file version which are in sync. E.g. 1.0.
9,71852436
open up the AssemblyInfo.cs file and change
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
you can do this in IDE by going to project -> properties -> assembly information
This however will only allow you to auto increment the Assembly version and will give you the
Assembly File Version: A wildcard ("*") is not allowed in this field
message box if you try place a * in the file version field.
So just open up the assemblyinfo.cs and do it manually.
54.7k53204342
7,14752333
Another option for changing version numbers in each build is to use the Version task of . Just download their installer, install it, then adapt the following code and paste it after &Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /& in your .csproj file:
&Import Project="$(MSBuildExtensionsPath)\munity.Tasks.Targets" /&
&Target Name="BeforeBuild"&
&Version VersionFile="Properties\version.txt" Major="1" Minor="0" BuildType="Automatic" StartDate="12/31/2009" RevisionType="BuildIncrement"&
&Output TaskParameter="Major" PropertyName="Major" /&
&Output TaskParameter="Minor" PropertyName="Minor" /&
&Output TaskParameter="Build" PropertyName="Build" /&
&Output TaskParameter="Revision" PropertyName="Revision" /&
&/Version&
&AssemblyInfo CodeLanguage="CS"
OutputFile="Properties\VersionInfo.cs"
AssemblyVersion="$(Major).$(Minor)"
AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" /&
Note: Adapt the StartDate property to your locale.
For the third build on January 14th, 2010, this creates a VersionInfo.cs with this content:
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.14.2")]
This file then has to be added to the project (via Add existing item), and the AssemblyVersion and AssemblyFileVersion lines have to be removed from AssemblyInfo.cs.
The different algorithms for changing the version components are described in $(MSBuildExtensionsPath)\munity.Tasks.chm and Version Properties.
5,37653040
Install the
add-in. It gives you way more control than the * option.
2,71622444
I came up with a solution similar to Christians but without depending on the Community MSBuild tasks, this is not an option for me as I do not want to install these tasks for all of our developers.
I am generating code and compiling to an Assembly and want to auto-increment version numbers. However, I can not use the VS 6.0.* AssemblyVersion trick as it auto-increments build numbers each day and breaks compatibility with Assemblies that use an older build number. Instead I want to have a hard-coded AssemblyVersion but a auto-incrementing AssemblyFileVersion. I've accomplished this by specifying AssemblyVersion in the AssemblyInfo.cs and generating a VersionInfo.cs in MSBuild like this,
&PropertyGroup&
&Year&$([System.DateTime]::Now.ToString("yy"))&/Year&
&Month&$([System.DateTime]::Now.ToString("MM"))&/Month&
&Date&$([System.DateTime]::Now.ToString("dd"))&/Date&
&Time&$([System.DateTime]::Now.ToString("HHmm"))&/Time&
&AssemblyFileVersionAttribute&[assembly:System.Reflection.AssemblyFileVersion("$(Year).$(Month).$(Date).$(Time)")]&/AssemblyFileVersionAttribute&
&/PropertyGroup&
&Target Name="BeforeBuild"&
&WriteLinesToFile File="Properties\VersionInfo.cs" Lines="$(AssemblyFileVersionAttribute)" Overwrite="true"&
&/WriteLinesToFile&
This will generate a VersionInfo.cs file with an Assembly attribute for AssemblyFileVersion where the version follows the schema of YY.MM.DD.TTTT with the build date. You must include this file in your project and build with it.
1,34431522
To get the version numbers try
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.AssemblyName assemblyName = assembly.GetName();
Version version = assemblyName.V
To set the version number, create/edit AssemblyInfo.cs
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
Also as a side note, the third number is the number of days since 2/1/2000 and the fourth number is half of the amount of total seconds in the day. So if you compile at midnight it should be zero.
10.3k34142254
49.9k2297109
Setting a * in the version number in AssemblyInfo or under project properties as described in the other posts does not work with all versions of Visual Studio / .NET.
Afaik it did not work in VS 2005 (but in VS 2003 and VS 2008). For VS 2005 you could use the following: .
But be aware that changing the version number automatically is not recommended for strong-named assemblies. The reason is that all references to such an assembly must be updated each time the referenced assembly is rebuilt due to the fact that strong-named assembly references are always a reference to a specific assembly version. Microsoft themselves change the version number of the .NET Framework assemblies only if there are changes in interfaces. (NB: I'm still searching for the link in MSDN where I read that.)
99.3k33175243
Set the version number to "1.0.*" and it will automatically fill in the last two number with the date (in days from some point) and the time (half the seconds from midnight)
69.4k20129214
It is in your project properties under Publish
5,37833754
7,65732041
Go to Project | Properties and then Assembly Information and then Assembly Version and put an * in the last or the second-to-last box (you can't auto-increment the Major or Minor components).
55k28136275
To get incrementing (DateTime) information into the AssemblyFileVersion property which has the advantage of not breaking any dependencies.
Building on Boog's solution (did not work for me, maybe because of VS2008?), you can use a combination of a pre-build event generating a file, adding that file (including its version properties) and then using a way to read out those values again. That is..
Pre-Build-Event:
echo [assembly:System.Reflection.AssemblyFileVersion("%date:~-4,4%.%date:~-7,2%%date:~-10,2%.%time:~0,2%%time:~3,2%.%time:~-5,2%")] & $(ProjectDir)Properties\VersionInfo.cs
Include the resulting VersionInfo.cs file (Properties subfolder) into your project
Code to get Date back (years down to seconds):
var version = assembly.GetName().V
var fileVersionString = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).FileV
Version fileVersion = new Version(fileVersionString);
var buildDateTime = new DateTime(fileVersion.Major, fileVersion.Minor/100, fileVersion.Minor%100, fileVersion.Build/100, fileVersion.Build%100, fileVersion.Revision);
Not very comfortable.. also, I do not know if it creates a lot of force-rebuilds (since a file always changes).
You could make it smarter for example if you only update the VersionInfo.cs file every few minutes/hours (by using a temporary file and then copying/overwriting the real VersionInfo.cs if a change large enough is detected). I did this once pretty successfully.
2,02721645
Use the AssemblyInfo task from the MSBuild Community Tasks () project, and integrate it into your .csproj/.vbproj file.
It has a number of options, including one to tie the version number to the date and time of day.
Recommended.
As of right now, for my application,
string ver = Application.ProductV
returns ver = 1.0.
The value 3251 is the number of days since 1/1/2000. I use it to put a version creation date on the splash screen of my application. When dealing with a user, I can ask the creation date which is easier to communicate than some long number.
(I'm a one-man dept supporting a small company. This approach may not work for you.)
17.9k42978
1,63422028
Changing the AssemblyInfo works in VS2012. It seems strange that there's not more support for this in Visual Studio, you'd think this was a basic part of the build/release process.
Maybe, for this task, you can use code like this:
private bool IncreaseFileVersionBuild()
if (System.Diagnostics.Debugger.IsAttached)
var fi = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.GetDirectories("Properties")[0].GetFiles("AssemblyInfo.cs")[0];
var ve = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
string ol = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + ve.FileBuildPart.ToString() + "." + ve.FilePrivatePart.ToString();
string ne = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + (ve.FileBuildPart + 1).ToString() + "." + ve.FilePrivatePart.ToString();
System.IO.File.WriteAllText(fi.FullName, System.IO.File.ReadAllText(fi.FullName).Replace("[assembly: AssemblyFileVersion(\"" + ol + "\")]", "[assembly: AssemblyFileVersion(\"" + ne + "\")]"));
and call it from form loading.
With this code you can update any part of file info in AssemblyInfo.cs (but you must use "standard" directory structure).
. Free. Open-source.
Each time I do a build it auto-increments the least-significant digit.
I don't have any idea how to update the others, but you should at least be seeing that already...
11.1k73664
I'm using this approach
by placing the T4 template in a "Solution Items" and using it with "Add as Link" within each project.
supports AssemblyInfo files patching. With cake in hands you have infinite ways to implement automatic version incrementing.
Simple example of incrementing version like C# compiler does:
Setup(() =&
// Executed BEFORE the first task.
var datetimeNow = DateTime.N
var daysPart = (datetimeNow - new DateTime()).D
var secondsPart = (long)datetimeNow.TimeOfDay.TotalSeconds/2;
var assemblyInfo = new AssemblyInfoSettings
Version = "3.0.0.0",
FileVersion = string.Format("3.0.{0}.{1}", daysPart, secondsPart)
CreateAssemblyInfo("MyProject/Properties/AssemblyInfo.cs", assemblyInfo);
Version - is assembly version. Best practice is to lock major version number and leave remaining with zeroes (like "1.0.0.0").
FileVersion - is assembly file version.
Note that you can patch not only versions but .
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 win2008 r2是什么意思 的文章

 

随机推荐