Solved

asp.net / c# issue

Posted on 2011-09-22
5
203 Views
Last Modified: 2012-05-12
I have a gridview, and data came from sql server.
On each row, I would like to add a link or button like <a href=aaa.aspx?PartNo=111>
When it is clicked, it will capture the PartNo (111) and generate a new web page
called 111.aspx and save into server root directory like c:\InetPub\www\project\111.aspx

is it possible? If yes, can you show me how to do it?

Thanks,
0
Comment
Question by:Webboy2008
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36581056
Add a button field to the grid column list and give it a command argument.

Create an OnRowCommand for the Grid.

In the OnRowCommand, check the e.CommandArgument for "CreatePage" or whatever you put in in step 1.

Make sure your DataKeys for the Grid are setup to include the PartNo so you can pull it in the OnRowCommand

Pull the PartNo from the Grid.DataKeys (e contains the RowIndex)

Use a filestream object to create your [PartNo].aspx file on the server
   - this will require the webuser to have read/write access to the folder you want to put it in.

0
 

Author Comment

by:Webboy2008
ID: 36582028
Strickdd:

I need some working sample. In addition, I just have one more question. Once the webpage is saved.
can I also write some aspx script there?
Like after PartNo.aspx is done, I want to add some thing like
<a href=asssasdf.aspx>Click here</a> inside of the webpage...is it possible?
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36582115
First off, I'm nost sure what you are trying to accomplish by this (frankly I don't care), but you can probably get away with one generic file that you display information based on querystring instead of creating a bunch of these .aspx files.

To answer your question:
Yes, if you follow the FileStream example link posted in the code section below, you will see how you can add any text to the file you wish.

<asp:GridView ID="PartsGrid" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataSourceID="QueueDecisionData" OnRowCommand="PartsGrid_RowCommand" DataKeyNames="PartsNo">
	<Columns>
		<asp:ButtonField ButtonType="button" Text="Edit" CausesValidation="false" CommandName="EditRow" ItemStyle-HorizontalAlign="center" />
	</Columns>
</asp:GridView>

protected void PartsGrid_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		if (e.CommandName == "EditRow")
		{
			//Filestream example:http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx
		}
	}

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 36587003
i would like to add aspx file.
and inside of aspx file, I would like to add some property like button and hidden field. is that possible?
0
 
LVL 28

Expert Comment

by:strickdd
ID: 36587542
yes, whatever you add to the filestream text will be added to the created .aspx file. You can add a button, you can add a hidden field, you can add the works of Shakespear if you want.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now