Hi tanweeruddinb...,
Refer below example.
HTML
<asp:ListView ID="lvQuestions" runat="server" GroupItemCount="1" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1" OnItemDataBound="lvQuestions_ItemDataBound">
<LayoutTemplate>
<table>
<tr>
<td>QuestionId</td>
<td>QuestionDes</td>
<td>QuestionChoice_1</td>
<td>QuestionChoice_2</td>
<td>QuestionChoice_3</td>
<td>Question_Correct_Choice</td>
<td>Question_Counter</td>
<td>Teacher_Id</td>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblId" Text='<%# Eval("QuestionId") %>' runat="server" />
</td>
<td><%# Eval("QuestionDes") %></td>
<td>
<asp:RadioButtonList runat="server" ID="rblQuestionChoice_1">
</asp:RadioButtonList></td>
<td>
<asp:RadioButtonList runat="server" ID="rblQuestionChoice_2">
</asp:RadioButtonList></td>
</td>
<td>
<asp:RadioButtonList runat="server" ID="rblQuestionChoice_3">
</asp:RadioButtonList></td>
</td>
<td><%# Eval("Question_Correct_Choice") %></td>
<td><%# Eval("Question_Counter") %></td>
<td><%# Eval("Teacher_Id") %></td>
</tr>
</ItemTemplate>
</asp:ListView>
Namespaces
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindQuestions();
}
}
protected void lvQuestions_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
string lblId = (e.Item.FindControl("lblId") as Label).Text;
string query = "SELECT QuestionChoice_1 FROM QuestionDescription WHERE QuestionId = " + lblId;
query += " UNION ";
query += " SELECT QuestionChoice_2 FROM QuestionDescription WHERE QuestionId = " + lblId;
query += " UNION ";
query += "SELECT QuestionChoice_3 FROM QuestionDescription WHERE QuestionId = " + lblId;
RadioButtonList rblChoice_1 = e.Item.FindControl("rblQuestionChoice_1") as RadioButtonList;
rblChoice_1.DataSource = GetData(query);
rblChoice_1.DataTextField = "QuestionChoice_1";
rblChoice_1.DataValueField = "QuestionChoice_1";
rblChoice_1.DataBind();
RadioButtonList rblchoice_2 = e.Item.FindControl("rblQuestionChoice_2") as RadioButtonList;
rblchoice_2.DataSource = GetData(query);
rblchoice_2.DataTextField = "QuestionChoice_1";
rblchoice_2.DataValueField = "QuestionChoice_1";
rblchoice_2.DataBind();
RadioButtonList rblchoice_3 = e.Item.FindControl("rblQuestionChoice_3") as RadioButtonList;
rblchoice_3.DataSource = GetData(query);
rblchoice_3.DataTextField = "QuestionChoice_1";
rblchoice_3.DataValueField = "QuestionChoice_1";
rblchoice_3.DataBind();
}
}
private void BindQuestions()
{
string query = "SELECT * FROM QuestionDescription";
lvQuestions.DataSource = GetData(query);
lvQuestions.DataBind();
}
private DataTable GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
Screenshot