Solved

asp.net / c# issue

Posted on 2011-09-22
5
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Suggested Courses

738 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