I am new to ASP.NET webforms and C#. I want to create a simple web application with the function of searching a specific student name from the XML document. The web app has a textbox where i can type the student name or id and click submit button it should retrieve the data of the student from the XML. How do i make this search function work form XML? The data user recieves should be independent not in gridview format, so i can style them to look like a graduation certificate.
Here is the sample that i have made:
nd I used a wild card search for the name - we could I suppose JUST match on say the start, but you can say search for "B", and you get this:
Of course, if you enter a number, then I search by ID, and say this
And I suppose we should add to the GV a "no data row, say like this:
<asp:GridView ID="GridView1" runat="server" CssClass="table" Width="40%">
<EmptyDataTemplate>
<h2>No data found</h2>
</EmptyDataTemplate>
</asp:GridView>
However, as noted, you do NOT want a grid format results.
So, we can just change the GV to say a repeoater, or datalist.
Lets use a data list.
So, our markup now becomes this:
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" >
</asp:DetailsView>
The code remains as before, execpt for this:
DetailsView1.DataSource = MyTable;
DetailsView1.DataBind();
And we now have the results in a FORM type of layout:
So be it a grid, or even just filling out controls on a page, the approach is quite much the same. There certainly no limits, or reason to use a grid for the results.
You also don't even have to use a auto bind control (say list details list).
You can simple drop in controls and lay them out anyway you want.
Say, like this:
<div style="border-style:solid;color:black;width:300px;float:left">
<div style="padding:5px;text-align:right">
<p>Student ID: <asp:TextBox ID="ID" runat="server" /></p>
<p>Student Name: <asp:TextBox ID="Student_Name" runat="server" /></p>
<p>Honours: <asp:TextBox ID="Honours" runat="server" /></p>
<p>Book Price: <asp:TextBox ID="Book_Price" runat="server" /></p>
<p>Program: <asp:TextBox ID="Programme" runat="server" /></p>
</div>
</div>
So above are just simple controls dropped into the page.
And now our code to fill out above would be:
(same as before, but now in place of a grid bind, or data list bind, we just use code to fill out the controls like this:
if (MyTable.DefaultView.Count > 0)
{
// we have a match - display it
DataRow OneRow = MyTable.DefaultView.ToTable().Rows[0];
ID.Text = OneRow["ID"].ToString();
Student_Name.Text = OneRow["STudent_Name"].ToString();
Honours.Text = OneRow["Honours"].ToString();
Book_Price.Text = OneRow["Book_Price"].ToString();
Programme.Text = OneRow["Programme"].ToString();
}
And the result is now this:
So sending the results to a grid, or just some code is really quite much the same process. In fact, as you can see, we swapped out the Grid view for a Details view. In other words JUST A CHANGE of 2 lines of code, and we had a details view in place of a gridview.
However, as noted, you obvious want to lay out that final result to any way you want - and not necessary a grid, or even a built in details view.
As you can see in the last example - it was a simple matter to grab/get the results of the filter into one nice simple DataRow object, and from that we just code out setting of the controls we dropped on the page. That sample layout I have could of course be any kind of layout you are able to dream up.