2

I want to bind data and display table record in Html table in asp.net web form, Using any method like foreach and for loop,

Like if you aware about this, That we can import namespace and and using class we can define datasource and getting ds variable in .Aspx page.

Same like in asp.net mvc, We are directly bind data in lable, textbox.

So thought by this way i want to doing speedlly data communication to database.

Please help me and given appropriate response of this question. Thanks

1 Answer 1

3

Aslam,

Yes you can declare a public variable/property in your aspx.cs class. You can assign that variable/property in Page_Load or any other appropriate event and then you can directly access it in your aspx.

following is the example:

public DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
    ds = new DataSet();
    //load your ds from database
}

Following is the code to use table 0 from database to create table in aspx

<table>
<% foreach(DataRow row in ds.Tables[0].Rows) { %>
<tr>
<td><%= row["columnName"] %></td>
</tr>
<% } %>
</table>

Hope this helps

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.