Hi RahulRock1,
Please refer the below code and modify as per your requirement.
HTML
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
QuestionsNo:
</td>
<td colspan="7">
<asp:TextBox ID="txtQuestionNo" runat="server" />
</td>
</tr>
<tr>
<td>
Question:
</td>
<td colspan="7">
<asp:TextBox ID="txtQuestion_detail" Width="400px" runat="server" />
</td>
</tr>
<tr>
<td>
OptionA:
</td>
<td>
<asp:TextBox ID="Option_1" runat="server" />
</td>
<td>
OptionB:
</td>
<td>
<asp:TextBox ID="Option_2" runat="server" />
</td>
</tr>
<tr>
<td>
OptionC:
</td>
<td>
<asp:TextBox ID="Option_3" runat="server" />
</td>
<td>
OptionD:
</td>
<td>
<asp:TextBox ID="Option_4" runat="server" />
</td>
</tr>
</table>
<br />
<asp:Button Text="Add Question" OnClick="OnClick" runat="server" />
<br />
<br />
<br />
<asp:GridView ID="GvQuestions" runat="server" />
</div>
</form>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DisplayRecord();
}
}
private void DisplayRecord()
{
DataSet Xds = new DataSet();
Xds.ReadXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"));
GvQuestions.DataSource = Xds;
GvQuestions.DataBind();
}
protected void OnClick(object sender, EventArgs e)
{
DataSet Xds = new DataSet();
Xds.ReadXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"));
DataRow Xrow = Xds.Tables[0].NewRow();
Xrow["Question_ID"] = "Question_" + txtQuestionNo.Text;
Xrow["Question_detail"] = txtQuestion_detail.Text.Trim();
Xrow["Option_1"] = Option_1.Text.Trim();
Xrow["Option_2"] = Option_2.Text.Trim();
Xrow["Option_3"] = Option_3.Text.Trim();
Xrow["Option_4"] = Option_4.Text.Trim();
Xrow["Radion_Button_index"] = "-1";
Xds.Tables[0].Rows.Add(Xrow);
Xds.AcceptChanges();
Xds.WriteXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"));
DisplayRecord();
}
Vb.net
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Me.DisplayRecord()
End If
End Sub
Private Sub DisplayRecord()
Dim Xds As New DataSet()
Xds.ReadXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"))
GvQuestions.DataSource = Xds
GvQuestions.DataBind()
End Sub
Protected Sub OnClick(sender As Object, e As EventArgs)
Dim Xds As New DataSet()
Xds.ReadXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"))
Dim Xrow As DataRow = Xds.Tables(0).NewRow()
Xrow("Question_ID") = "Question_" + txtQuestionNo.Text
Xrow("Question_detail") = txtQuestion_detail.Text.Trim()
Xrow("Option_1") = Option_1.Text.Trim()
Xrow("Option_2") = Option_2.Text.Trim()
Xrow("Option_3") = Option_3.Text.Trim()
Xrow("Option_4") = Option_4.Text.Trim()
Xrow("Radion_Button_index") = "-1"
Xds.Tables(0).Rows.Add(Xrow)
Xds.AcceptChanges()
Xds.WriteXml(Server.MapPath("~/Student_ExamPaper_xml/Student_Question_paper_xml.xml"))
DisplayRecord()
End Sub
Screenshot