asp.net database binding to DataList control action method

Source: Internet
Author: User

I'm going to do this page now, and then I use the DataList control to display the title, and I want to ask how to bind the title of my database tutorial to the DataList control, and then let it show the exam questions?

Workaround 1:
DataList DataBind ()

Workaround 2:
View detailed information on MSDN

Workaround 3:
Use table tables in DataList templates, such as: <asp Tutorials: DataList id= "Dldetailedinfo" runat= "Server" onitemdatabound= "Dldetailedinfo_ ItemDataBound "
Width= "100%" >
<ItemTemplate>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" class= "Tablebtitle" >
<tr>
<th colspan= "2" scope= "col" >
Xingyang find a job on the Xingyang talent Network or Xingyang Life network </th>
</tr>
<tr>
&LT;TD width= "25%" class= "Tablegrayright" >
Mining Machinery Encyclopedia network can be Free Inquiry ball mill and other mining equipment capital </td>
&LT;TD class= "Tablenoneleft" >
<asp:label id= "Lbltypename" runat= "server" text= ' <%# Eval ("TypeName")%> ' ></asp:Label>
</td><!--Zhengzhou To do the site to find a new Fulcrum network </tr>
</table>
</ItemTemplate>
</asp:DataList>

Workaround 4:
The text of your control uses <%# Eval ("title Field name")%>
For example: txext= ' <%# Eval ("title")%> '

Bind Paging Implementation

The Dlbind method is a custom no return value type method that is used primarily to query a record from a database for a specified condition and bind to a DataList control, and then by setting the AllowPaging property of the PagedDataSource class object to True, To implement the paging functionality of the DataList control. The Dlbind method implements the code as follows:

public void Dlbind ()

{

int curpage = Convert.ToInt32 (This.labPage.Text);

PagedDataSource PS Tutorial = new PagedDataSource ();

Sqlcon = new SqlConnection (Strcon);

Sqlcon. Open ();

String sqlstr = "Select a.*,b.* from Tb_card as a join Tb_module as B on A.moduleid=b.moduleid";

SqlDataAdapter myadapter = new SqlDataAdapter (Sqlstr, Sqlcon);

DataSet ds = new DataSet ();

Myadapter.fill (ds, "Tb_card");

Ps. DataSource = ds. tables["Tb_card"]. DefaultView;

Ps. AllowPaging = true; Whether you can page pagination

Ps. PageSize = 2; Number of Displays

Ps. CurrentPageIndex = curpage-1; Get the page number of the current page

This.lnkbtnUp.Enabled = true;

This.lnkbtnNext.Enabled = true;

This.lnkbtnBack.Enabled = true;

This.lnkbtnOne.Enabled = true;

if (curpage = 1)

{

this.lnkbtnOne.Enabled = false;//does not display the first page button

this.lnkbtnUp.Enabled = false;//does not display the previous page button

}

if (Curpage = PS. PageCount)

{

this.lnkbtnNext.Enabled = false;//does not display next page

this.lnkbtnBack.Enabled = false;//does not display the last page

}

This.labBackPage.Text = Convert.ToString (PS. PageCount);

This.dlContent.DataSource = PS;

This.dlContent.DataKeyField = "Cardid";

This.dlContent.DataBind ();

Sqlcon. Close ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.