hello sir while i am converting datalist to pdf it diplays below error:
Control 'DataList1_ctl00_RadioButton1' of type 'RadioButton' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control 'DataList1_ctl00_RadioButton1' of type 'RadioButton' must be placed inside a form tag with runat=server.
Source Error:
Line 52: StringWriter sw = new StringWriter();
Line 53: HtmlTextWriter hw = new HtmlTextWriter(sw);
Line 54: DataList1.RenderControl(hw);
Line 55:
Line 56: StringReader sr = new StringReader(sw.ToString());
|
protected void Button1_Click1(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Respiratory.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
DataList1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfdoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfdoc);
PdfWriter.GetInstance(pdfdoc, Response.OutputStream);
pdfdoc.Open();
htmlparser.Parse(sr);
pdfdoc.Close();
Response.Write(pdfdoc);
Response.End();
}
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>(<%#Container.ItemIndex+1 %>)
<asp:Label ID="Label1" runat="server" Text='<%# bind("ques1") %>' Font-Bold="True"></asp:Label><br />
<table>
<tr>
<td >
<asp:RadioButton ID="RadioButton1" onclick="RadioCheck(this);" runat="server" GroupName="Questions" Text='<%# bind("ans1") %>' /></td>
</tr>
<tr>
<td >
<asp:RadioButton ID="RadioButton2" onclick="RadioCheck(this);" runat="server" GroupName="Questions" Text='<%# bind("ans2") %>' /></td>
</tr>
<tr>
<td >
<asp:RadioButton ID="RadioButton3" onclick="RadioCheck(this);" runat="server" GroupName="Questions" Text='<%# bind("ans3") %>' /></td>
</tr>
<tr>
<td >
<asp:RadioButton ID="RadioButton4" onclick="RadioCheck(this);" runat="server" GroupName="Questions" Text='<%# bind("ans4") %>' /></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList></td>
<td style="width: 50%" valign="top" align="right">
<h2>
Your answers
</h2>
<table id="tbQuestion">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<itemtemplate>
<%#Container.ItemIndex+1 %>
</itemtemplate>
</td>
<td>
<asp:RadioButton ID="rblOptionOne" runat="server" GroupName="Answer" />
</td>
<td>
<asp:RadioButton ID="rblOptionTwo" runat="server" GroupName="Answer" />
</td>
<td>
<asp:RadioButton ID="rblOptionThree" runat="server" GroupName="Answer" />
</td>
<td>
<asp:RadioButton ID="rblOptionFour" runat="server" GroupName="Answer" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>