ASP.NET - how to create a page like below diagram.

Asked By aman on 10-Nov-11 09:35 AM
hi all,



i want to create a page for Question and their respective options but finding it difficult......how to do so...

please help me with some good example.

thanks.
dipa ahuja replied to aman on 10-Nov-11 09:45 AM
Untitled document
1. Do You have cell phone?<br />
     <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
       <asp:ListItem>yes</asp:ListItem>
       <asp:ListItem>no</asp:ListItem>
     </asp:RadioButtonList>
2. Do you have LandLine Phone?<br />
     <asp:RadioButtonList ID="RadioButtonList2" runat="server">
       <asp:ListItem>yes</asp:ListItem>
       <asp:ListItem>no</asp:ListItem>
     </asp:RadioButtonList>
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
    <asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
 
.CS
 
protected void Button1_Click(object sender, EventArgs e)
{
  lblResult.Text = "";
 
  lblResult.Text ="Your First Ans :" + RadioButtonList1.SelectedItem.ToString();
  lblResult.Text = lblResult.Text + "Your Second Answer " +      RadioButtonList2.SelectedItem.ToString();

}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
   Response.Write("you have selected " + RadioButtonList1.SelectedItem.Text.ToString());
}
kalpana aparnathi replied to aman on 10-Nov-11 12:52 PM
Try this code:
private void Form1_Load(object sender, EventArgs e)
      {
     public static string path = @"yourfile.xlsx";
     string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

        try
        {

          System.Data.OleDb.OleDbConnection MyConnection;

          System.Data.DataSet DtSet;

          System.Data.OleDb.OleDbDataAdapter MyCommand;

          MyConnection = new System.Data.OleDb.OleDbConnection(connStr);

          MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);

          MyCommand.TableMappings.Add("Table", "TestTable");

          DtSet = new System.Data.DataSet();

          MyCommand.Fill(DtSet);

       
          MyConnection.Close();

        }

        catch (Exception ex)
        {

          //MessageBox.Show(ex.ToString());

        }
}


Design code:

<html>
<body>

<form runat="server">
<asp:Repeater id="qdata" runat="server">

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>question</th>
<th>A1</th>
<th>A2</th>
<th>A3</th>
<th>A4</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%#Container.DataItem("question")%></td>
<td><%#Container.DataItem("A1")%></td>
<td><%#Container.DataItem("A2")%></td>
<td><%#Container.DataItem("A3")%></td>
<td><%#Container.DataItem("A4")%></td>
</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>
</form>

</body>
</html>