By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Display .htm files content in .aspx page control

P: 30
Dear sir,

I have a word document file contains text and images, now i have saved it as a web page and wants to display it on browser ,
using ,
string str=directory.getfiles("");
response.contentType="text/html";
response .writefile("");
it displayed in different format and images not shown
blank spaces shown as ?????????? and image as X.

i have no. of files stored as word file ,tried to display directly in gridview but it's not posible for me, so i converted them as web page and now i want to display 5 files dynamically in gridview including images., so help me out, looking for ur reply..

, can u tell me how it works, i will be thanxfull to u

i do not want to use web browser or process.start(" IExploreAsassr.exe","path") method because it displays only one file at a time , actually i want to dislay it in gridview item template, including pics.
Aug 20 '09 #1

✓ answered by Frinavale

@shashi shekhar singh
Ok, that wont work, your 1.htm file has to be located on the web server. That way web browsers can down load it using the URL specified as the src attribute.

You can't use a local file path to the 1.htm file...you have to use something like "http://localhost/mywebsite/statichtm/1.htm".

So, place all of the htm files into a folder located within your project. Then loop through the directory and create the URL based on the files you find there.

So you would have something like this to create the URLs:

Expand|Select|Wrap|Line Numbers
  1. string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
  2. List<string> staticHtmUrls= new List<string>();
  3.  
  4. for (int i = 1; i < getfile.Length; i++)
  5. {     string staticURL = "/statichtm/"+getfile[i];
  6.       staticHtmUrls.Add(staticURL );       
  7. }
So now you have a list of URLs to your static htm files.

I'm thinking that it will probably be easier for you to use a Repeater instead of a GridView.

So your ASP code would look like:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="staticWebPagesRepeater" runat="server">
  2.         <HeaderTemplate>
  3.              <table border="1">
  4.                 <tr>
  5.                    <td><b>Web Pages</b></td>
  6.                 </tr>
  7.           </HeaderTemplate>
  8.           <ItemTemplate>
  9.              <tr>
  10.                 <td> <iframe src="<%# Container.DataItem %>"></iframe></td>
  11.              </tr>
  12.           </ItemTemplate>
  13.           <FooterTemplate>
  14.              </table>
  15.           </FooterTemplate>
  16. </asp:Repeater>
And your C# code would have something like this:
Expand|Select|Wrap|Line Numbers
  1. private List<string> _repSource;
  2. protected void Page_Load(Object sender, System.EventArgs e) 
  3. {
  4.         _repSource =  new List<string>();
  5.         string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
  6.         foreach (string name in fileNames)
  7.         {
  8.             string sp[] = name.Split('\');
  9.             string urlToStaticHTML = sp(sp.Length - 1);
  10.             _repSource.Add("/StaticHTM/" + urlToStaticHTML );
  11.         }
  12.         staticWebPagesRepeater.DataSource = _repSource.ToArray();
  13.         staticWebPagesRepeater.DataBind();
  14. }
  15.  

Share this Question
Share on Google+
23 Replies


100+
P: 270
well, you can use <iframe> tag

Expand|Select|Wrap|Line Numbers
  1. <iframe src ="myFilePath.html" width="100%" height="300">
  2.   <p>iframes not supported</p>
  3. </iframe>
Aug 20 '09 #2

100+
P: 270
in response.write("") pass parameter for showing the iframe tag with the desired file...

cheers,
Nitin
Aug 20 '09 #3

ssnaik84
100+
P: 149
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <meta http-equiv="Content-Type" content="application/doc">
  4. </head>
  5. <body>
  6.     <iframe src="your-word-document-file.doc" width="100%" height="100%"> </iframe>
  7. </body>
  8. </html>
try this.
Aug 21 '09 #4

Frinavale
Expert Mod 5K+
P: 9,731
Hi Shashi,

Have you tired viewing the HTML webpages generated by Word by themselves first?

Make sure that they display correctly before trying to use them in your asp application.

If they are working, consider using IFrames to display the webpages in the grid.
Aug 24 '09 #5

P: 30
i am really respectfull to u all for ur reply, i want to use like this shown as below,
Expand|Select|Wrap|Line Numbers
  1.  
  2. <div>
  3.         <iframe id="iframe1" runat="server" scrolling="auto"  width="100%" height="100%"> </iframe>
  4.  
  5.     </div>  
Expand|Select|Wrap|Line Numbers
  1.   string[] getfile = Directory.GetFiles(@"D:\Shekhar Documents", "*.htm");
  2.             for (int i = 1; i < getfile.Length; i++)
  3.            {
  4.                HtmlControl frame = (HtmlControl)this.FindControl("iframe1");
  5.                //string path = Server.MapPath("1.htm");
  6.                frame.Attributes["src"] = getfile[i];
  7.            }
i am using this but it not displayed my file content, it only displayed http url.. like "http://www.google.com", please help me out.. i am waiting for ur reply.
Aug 25 '09 #6

100+
P: 270
try displaying only single file on the page @shashi shekhar singh
Aug 25 '09 #7

P: 30
Like
frame.Attributes["src"] = getfile[i];
I am giving
frame.Attributes["src"] = "D://shekhardocuments/1.htm";
then it's not displaying , am new for iframe so plzgive me reply.
Aug 26 '09 #8

100+
P: 270
@shashi shekhar singh
The src attribute should be internet url e.g. http://localhost/shekhardocuments/1.htm

and also you should add the html files in the project directory..
Aug 26 '09 #9

Frinavale
Expert Mod 5K+
P: 9,731
@shashi shekhar singh
Ok, that wont work, your 1.htm file has to be located on the web server. That way web browsers can down load it using the URL specified as the src attribute.

You can't use a local file path to the 1.htm file...you have to use something like "http://localhost/mywebsite/statichtm/1.htm".

So, place all of the htm files into a folder located within your project. Then loop through the directory and create the URL based on the files you find there.

So you would have something like this to create the URLs:

Expand|Select|Wrap|Line Numbers
  1. string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
  2. List<string> staticHtmUrls= new List<string>();
  3.  
  4. for (int i = 1; i < getfile.Length; i++)
  5. {     string staticURL = "/statichtm/"+getfile[i];
  6.       staticHtmUrls.Add(staticURL );       
  7. }
So now you have a list of URLs to your static htm files.

I'm thinking that it will probably be easier for you to use a Repeater instead of a GridView.

So your ASP code would look like:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="staticWebPagesRepeater" runat="server">
  2.         <HeaderTemplate>
  3.              <table border="1">
  4.                 <tr>
  5.                    <td><b>Web Pages</b></td>
  6.                 </tr>
  7.           </HeaderTemplate>
  8.           <ItemTemplate>
  9.              <tr>
  10.                 <td> <iframe src="<%# Container.DataItem %>"></iframe></td>
  11.              </tr>
  12.           </ItemTemplate>
  13.           <FooterTemplate>
  14.              </table>
  15.           </FooterTemplate>
  16. </asp:Repeater>
And your C# code would have something like this:
Expand|Select|Wrap|Line Numbers
  1. private List<string> _repSource;
  2. protected void Page_Load(Object sender, System.EventArgs e) 
  3. {
  4.         _repSource =  new List<string>();
  5.         string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
  6.         foreach (string name in fileNames)
  7.         {
  8.             string sp[] = name.Split('\');
  9.             string urlToStaticHTML = sp(sp.Length - 1);
  10.             _repSource.Add("/StaticHTM/" + urlToStaticHTML );
  11.         }
  12.         staticWebPagesRepeater.DataSource = _repSource.ToArray();
  13.         staticWebPagesRepeater.DataBind();
  14. }
  15.  
Aug 26 '09 #10

P: 30
Respected Sir @Frinavale
I have used as u have explained by using repeater with iframe and the url , but i am geting error ...
C# Code:
Expand|Select|Wrap|Line Numbers
  1. //string[] getfile = Directory.GetFiles(Server.MapPath("~/statichtm/"), "*.htm");
  2.         string[] getfile = Directory.GetFiles(@"D:\Shekhar Documents\Tutorial + Development\html\Question_Html","*.htm");
  3.        List<string> staticHtmUrls = new List<string>();
  4.  
  5.         for (int i = 1; i < getfile.Length; i++)
  6.         {
  7.             string staticURL = "/statichtm/" + getfile[i];
  8.             staticHtmUrls.Add(staticURL);
  9.         }
  10.         staticWebPagesRepeater.DataSource = staticHtmUrls.ToArray();
  11.         staticWebPagesRepeater.DataBind(); 
  12.  
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="staticWebPagesRepeater" runat="server"> 
  2.         <HeaderTemplate> 
  3.              <table border="1"> 
  4.                 <tr> 
  5.                    <td><b>Web Pages</b></td> 
  6.                 </tr> 
  7.           </HeaderTemplate> 
  8.           <ItemTemplate> 
  9.              <tr> 
  10.                 <td> <iframe src="<%# Container.DataItem %></td>"></iframe></td> 
  11.              </tr> 
  12.           </ItemTemplate> 
  13.           <FooterTemplate> 
  14.              </table> 
  15.           </FooterTemplate> 
  16. </asp:Repeater> 
  17.  
  18.     </div>
Error is:
Server Error in '/bytes' Application.
--------------------------------------------------------------------------------

HTTP Error 400 - Bad Request.

--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 9.0.0.0
one thing that i forgot to explain to you. My original source file was of word Document type(MS word 2007) (text + image), i converted them in to .htm file, so when i add all files(.htm+image folders) into Visual Studio Solution Explorer and open to view in browser the error is:
Server Error in '/bytes' Application.
--------------------------------------------------------------------------------

HTTP Error 403 - Forbidden.

--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 9.0.0.0
looking for your reply it's urgent for me..
Aug 27 '09 #11

Frinavale
Expert Mod 5K+
P: 9,731
Well there are a couple of reasons why this wont work.

I didn't fully test the code because I was just quickly giving you an example and thought that you'd be able to figure it out from there. I work mainly in VB.NET and so I didn't test the loop that you had in your code already...needless to say I did not test the code, it was just an example.

The first problem with the code I posted is that I accidentally left a "<td>" in the src attribute in the ASP code....the ASP code should be:
Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="staticWebPagesRepeater" runat="server">
  2.         <HeaderTemplate>
  3.              <table border="1">
  4.                 <tr>
  5.                    <td><b>Web Pages</b></td>
  6.                 </tr>
  7.           </HeaderTemplate>
  8.           <ItemTemplate>
  9.              <tr>
  10.                 <td> <iframe src="<%# Container.DataItem %>"></iframe></td>
  11.              </tr>
  12.           </ItemTemplate>
  13.           <FooterTemplate>
  14.              </table>
  15.           </FooterTemplate>
  16. </asp:Repeater>
The second thing that is wrong with this code is that when you use the Directory.GetFiles() method it returns you a list of Path And File Names that match the pattern you're searching for.

We stated earlier that you cannot have a local path to a file because the web browser will not be able to download it...web browsers cannot access local files on your computer, it can only access files that exist on the web server and can only do so using a URL. You need to create a URL using the file name.

Because we simply prepended the "/statichtm/" to the file name, and didn't properly extract the name of the file from the Path/FileName your Urls are going to look like:

"/statichtm/D:\PatToVisualStudioProject\1.htm"

Obviously this is not a valid URL....what you really want is just:

"/statichtm/1.htm"

This would have been very obvious if you had used the debugger and stepped through the code.

So what you need to do is fix the ASP code so that the "<td>" is not part of the iframe's src attribute, and modify your loop so that it extracts the file name and then properly create the URLs by prepending "/statichtm/" to the file name extracted.

This is the working VB.NET version of what your code should look like.
Expand|Select|Wrap|Line Numbers
  1. Private _repSource As List(Of String)
  2. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  3.         _repSource = New List(Of String)
  4.         Dim fileNames() As String = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm")
  5.         For Each name In fileNames
  6.             Dim sp() As String = name.Split("\"c)
  7.             Dim urlToStaticHTML As String = sp(sp.Length - 1)
  8.             _repSource.Add("/StaticHTM/" + urlToStaticHTML)
  9.         Next
  10.         staticWebPagesRepeater.DataSource = _repSource.ToArray
  11.         staticWebPagesRepeater.DataBind()
  12. End Sub
  13.  

C# would look something like (the following is obviously not tested):
Expand|Select|Wrap|Line Numbers
  1. private List<string> _repSource;
  2. protected void Page_Load(Object sender, System.EventArgs e) 
  3. {
  4.         _repSource =  new List<string>();
  5.         string fileNames[] = Directory.GetFiles(Server.MapPath("~/StaticHTM/"), "*.htm");
  6.         foreach (string name in fileNames)
  7.         {
  8.             string sp[] = name.Split('\');
  9.             string urlToStaticHTML = sp(sp.Length - 1);
  10.             _repSource.Add("/StaticHTM/" + urlToStaticHTML );
  11.         }
  12.         staticWebPagesRepeater.DataSource = _repSource.ToArray();
  13.         staticWebPagesRepeater.DataBind();
  14. }
In the future, please try to debug the problem before automatically asking for help.
Aug 27 '09 #12

P: 30
@Frinavale

Thank you very much Sir,
I have gotted what i had to do.
thanks a lot again....
u have given a nice answer and made a nice conversetion to me. i really respect u..
bye.. have a nice day
Aug 28 '09 #13

P: 30
Respected Sir,
thanx a lot for your help now i am facing some other problem . Now i have to display these selected files into gridview/repeater 5 files per page and want to make a custom next and previous button so that when user click next button it's selected radio button item inserted into database and next remaining files will be displayed on the gridview/ repeater template.
Looking for ur reply..
Aug 31 '09 #14

Frinavale
Expert Mod 5K+
P: 9,731
Hi Shashi,

Please take the time to research the problem before you post your question. The experts here are more than willing to help you with a specific problem but you have to do your part to learn the basics.

Once you've tried to solve the problem and you need some help, ask for help on your specific problem.
Aug 31 '09 #15

P: 30
@Frinavale
Respected Sir....

i have a gridview inside them a radiobuttonlist taken by me.
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="QuestionView1" runat="server" AutoGenerateColumns="False" 
  2.             Width="262px" PageSize="3" AllowPaging="True">
  3.         <PagerSettings NextPageText="" PreviousPageText="" Visible="False" />
  4.         <Columns>
  5.             <asp:TemplateField HeaderText="Questions">
  6.             <ItemTemplate> 
  7.              <tr> 
  8.                 <td> <iframe src="<%# Container.DataItem %>" height="450" width="800"></iframe></td> 
  9.              </tr> 
  10.            <tr>
  11.              <td align="center" bgcolor="Yellow">
  12.             <asp:RadioButtonList ID="Answerlist" runat="server" RepeatDirection="Horizontal" ID="radiolist"  Font-Bold="True" ForeColor="#0099FF" TextAlign="Left">
  13.              <asp:ListItem Value="001" Text="Answer 1" ></asp:ListItem>
  14.              <asp:ListItem Value="002" Text="Answer 2"></asp:ListItem>
  15.              <asp:ListItem Value="003" Text="Answer 3"></asp:ListItem>
  16.              <asp:ListItem Value="004" Text="Answer 4"></asp:ListItem>
  17.  
  18.              </asp:RadioButtonList>
  19.              </td>
  20.  
  21.              </tr>
  22.           </ItemTemplate> 
  23.  
  24.  
  25.             </asp:TemplateField>
  26.         </Columns>
  27.  
  28.         </asp:GridView>
but when itry to findout whic radio button has been clicked it shows error, i am really tired .
Expand|Select|Wrap|Line Numbers
  1. RadioButtonList rdo = (RadioButtonList)QuestionView1.Rows[0].FindControl("Answerlist");
  2.         Response.Write("value has been selected" + rdo.SelectedValue + "<br/>");
looking for your reply....
From Shashi shekhar singh
Sep 4 '09 #16

Frinavale
Expert Mod 5K+
P: 9,731
Hmmm,

What you've posted looks fine...what is the error?
Are you calling the DataBind method for the GridView somewhere near the beginning of the ASP page life cycle (like in the Page Load event)?

-Frinny

PS. I'm not a Sir ;)
Sep 4 '09 #17

P: 30
@Frinavale
yes sir..
i bind the gridview on page _load and different button click of page like next ,previous, first and last button...
help me out looking for your reply..
Sep 7 '09 #18

Frinavale
Expert Mod 5K+
P: 9,731
Move the databind to the PreRender event instead.
Sep 7 '09 #19

P: 30
@Frinavale
thank you very much sir, i have got it..that i needed.
Sep 9 '09 #20

P: 30
Respected Sir,
thanx a lot for your support with me.
This time I have a gridview with multiple button controls inside gridview item template.now i have to check it, out side of the gridview button click event to know which button has been clicked. i am sending my .aspx page plz check it and help me out..
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  2.             AllowPaging="True" Height="197px" PageSize="1" Width="406px">
  3.             <PagerSettings Visible="False" />
  4.             <Columns>
  5.                 <asp:TemplateField HeaderText="Select Questions">
  6.                     <ItemTemplate>
  7.                         <table class="style1">
  8.                             <tr>
  9.                                 <td class="style2">
  10.                                     <asp:Button ID="Button1" runat="server" Height="26px" Text="1" Width="46px" 
  11.                                         onclick="Button1_Click" />
  12.                                 </td>
  13.                                 <td class="style3">
  14.                                     <asp:Button ID="Button2" runat="server" Height="28px" Text="2" Width="49px" 
  15.                                         onclick="Button2_Click" />
  16.                                 </td>
  17.                                 <td class="style4">
  18.                                     <asp:Button ID="Button3" runat="server" Height="29px" Text="3" Width="48px" 
  19.                                         onclick="Button3_Click" />
  20.                                 </td>
  21.                                 <td class="style4">
  22.                                     <asp:Button ID="Button4" runat="server" Height="27px" Text="4" Width="50px" 
  23.                                         onclick="Button4_Click" />
  24.                                 </td>
  25.                                 <td class="style5">
  26.                                     <asp:Button ID="Button5" runat="server" Height="26px" Text="5" Width="48px" 
  27.                                         onclick="Button5_Click" />
  28.                                 </td>
  29.                             </tr>
  30.                             <tr>
  31.                                 <td class="style2">
  32.                                     <asp:Button ID="Button6" runat="server" Height="28px" Text="6" Width="45px" 
  33.                                         onclick="Button6_Click" />
  34.                                 </td>
  35.                                 <td class="style3">
  36.                                     <asp:Button ID="Button7" runat="server" Height="29px" Text="7" Width="46px" 
  37.                                         onclick="Button7_Click" />
  38.                                 </td>
  39.                                 <td class="style4">
  40.                                     <asp:Button ID="Button8" runat="server" Height="26px" Text="8" Width="49px" 
  41.                                         onclick="Button8_Click" />
  42.                                 </td>
  43.                                 <td class="style4">
  44.                                     <asp:Button ID="Button9" runat="server" Height="30px" Text="9" Width="49px" 
  45.                                         onclick="Button9_Click" />
  46.                                 </td>
  47.                                 <td class="style5">
  48.                                     <asp:Button ID="Button10" runat="server" Height="26px" Text="10" Width="47px" 
  49.                                         onclick="Button10_Click" />
  50.                                 </td>
  51.                             </tr>
  52.                             <tr>
  53.                                 <td class="style2">
  54.                                     <asp:Button ID="Button11" runat="server" Height="27px" Text="11" Width="44px" 
  55.                                         onclick="Button11_Click" />
  56.                                 </td>
  57.                                 <td class="style3">
  58.                                     <asp:Button ID="Button12" runat="server" Height="27px" Text="12" Width="47px" 
  59.                                         onclick="Button12_Click" />
  60.                                 </td>
  61.                                 <td class="style4">
  62.                                     <asp:Button ID="Button13" runat="server" Height="29px" Text="13" Width="50px" 
  63.                                         onclick="Button13_Click" />
  64.                                 </td>
  65.                                 <td class="style4">
  66.                                     <asp:Button ID="Button14" runat="server" Height="30px" Text="14" Width="47px" 
  67.                                         onclick="Button14_Click" />
  68.                                 </td>
  69.                                 <td class="style5">
  70.                                     <asp:Button ID="Button15" runat="server" Height="28px" Text="15" Width="45px" 
  71.                                         onclick="Button15_Click" />
  72.                                 </td>
  73.                             </tr>
  74.                             <tr>
  75.                                 <td class="style2">
  76.                                     <asp:Button ID="Button16" runat="server" Height="31px" Text="16" Width="47px" 
  77.                                         onclick="Button16_Click" />
  78.                                 </td>
  79.                                 <td class="style3">
  80.                                     <asp:Button ID="Button17" runat="server" Height="32px" Text="17" Width="45px" 
  81.                                         onclick="Button17_Click" />
  82.                                 </td>
  83.                                 <td class="style4">
  84.                                     <asp:Button ID="Button18" runat="server" Height="29px" Text="18" Width="45px" 
  85.                                         onclick="Button18_Click" />
  86.                                 </td>
  87.                                 <td class="style4">
  88.                                     <asp:Button ID="Button19" runat="server" Height="30px" Text="19" Width="47px" 
  89.                                         onclick="Button19_Click" />
  90.                                 </td>
  91.                                 <td class="style5">
  92.                                     <asp:Button ID="Button20" runat="server" Height="32px" Text="20" Width="49px" 
  93.                                         onclick="Button20_Click" />
  94.                                 </td>
  95.                             </tr>
  96.                         </table>
  97.                     </ItemTemplate>
  98.                 </asp:TemplateField>
  99.                 <asp:TemplateField HeaderText="Your Question">
  100.                 <ItemTemplate>
  101.                 <iframe src="<%# Container.DataItem %>" style="height: 369px; width: 690px;" ></iframe>
  102.  
  103.                 </ItemTemplate>
  104.  
  105.                 </asp:TemplateField>
  106.             </Columns>
  107.         </asp:GridView>
  108.  <asp:Button ID="Button21" runat="server" Height="38px" onclick="Button21_Click"  Text="Start Test" Width="99px" />
  109.  
as shown above i want to check it which button has been clicked on
Expand|Select|Wrap|Line Numbers
  1. Button21_Click(object sender, eventargs e)
  2. {
  3.  
  4. }
plz help me out..waiting for your reply..
Sep 9 '09 #21

Frinavale
Expert Mod 5K+
P: 9,731
This one's a bit tricky.

The only time I've really done something like this I was using dynamic columns and dynamic TemplateFields. The code I implemented for the TemplateField would handle the onclick event and then raise it again so that the page code could handle it.

My guess would be that you'll have to use the GridView.RowCommand event. Remember that the first parameter is the Object that raised the event (which could be your button, but could be something else too)

-Frinny
Sep 9 '09 #22

P: 30
@Frinavale
When Button out side of the gridview has been clicked then how to determine which button raises the event to to give the source of iframe. ok if i found them by giving the condition
on submit button click...
Expand|Select|Wrap|Line Numbers
  1. if(gridview1.pageindex==0 && btn.text="1")
  2. {
  3.   btn1.enabled =false;
  4. }
then it is true only for one postback when next button inside the gridview clicked then it's enabled property =true.
i want to do when submit button clicked then the buutton inside the gridview who raises the src to iframe should be disabled for application lifetime.
Is it possible plz tel me how..it will be possible.
and also tell me how to raise the row_command event in gridview
Expand|Select|Wrap|Line Numbers
  1.  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
  2.             AllowPaging="True" Height="197px" PageSize="1" Width="406px" 
  3.             onrowcommand="GridView1_RowCommand">
  4.             <PagerSettings Visible="False" />
  5.             <Columns>
  6.                 <asp:TemplateField HeaderText="Select Questions">
  7.                     <ItemTemplate>
  8. </ItemTemplate>
Expand|Select|Wrap|Line Numbers
  1. void GridView1_RowCommand(objectsender,GridViewCommandEventArgs e)
  2.     {
  3.         foreach (GridViewRow row in GridView1.Rows)
  4.         {
  5.             Button one = row.FindControl("Button1") as Button;
  6.             Button two = row.FindControl("Button2") as Button;
  7.             Button three = row.FindControl("Button3") as Button;
  8.             Button four = row.FindControl("Button4") as Button;
  9.             Button five = row.FindControl("Button5") as Button;
  10.             Button six = row.FindControl("Button6") as Button;
  11.             Button seven = row.FindControl("Button7") as Button;
  12.             Button eight = row.FindControl("Button8") as Button;
  13.             Button nine = row.FindControl("Button9") as Button;
  14.             Button ten = row.FindControl("Button10") as Button;
  15.             Button eleven = row.FindControl("Button11") as Button;
  16.             Button twelve = row.FindControl("Button12") as Button;
  17.             Button thirteen = row.FindControl("Button13") as Button;
  18.             Button fourteen = row.FindControl("Button14") as Button;
  19.             if (GridView1.PageIndex == 0 && one.Text == "1")
  20.             {
  21.                 one.Enabled = false;
  22.  
  23.             }
  24.             if (GridView1.PageIndex == 1 && two.Text == "2")
  25.             {
  26.                 two.Enabled = false;
  27.  
  28.             }
  29.             if (GridView1.PageIndex == 2 && three.Text == "3")
  30.  
  31.             {
  32.                 three.Enabled = false;
  33.  
  34.             }
  35.             string name = e.CommandName;
  36.             switch (e.CommandName)
  37.             { 
  38.                 case "1":
  39.                     one.Enabled = false;
  40.                     break;
  41.                 case "2":
  42.                     two.Enabled = false;
  43.                     break;
  44.  
  45.             }
  46.         }
Sep 11 '09 #23

Frinavale
Expert Mod 5K+
P: 9,731
I should have looked at your code more closely.
I though you were using CommandField buttons not actual Buttons.
Please look into seeing if CommandField controls could be any help to you.
Sep 11 '09 #24

Post your reply

Sign in to post your reply or Sign up for a free account.