实验报告六ADONET中的数据绑定Word文档格式.docx
- 文档编号:22446149
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:15
- 大小:164.25KB
实验报告六ADONET中的数据绑定Word文档格式.docx
《实验报告六ADONET中的数据绑定Word文档格式.docx》由会员分享,可在线阅读,更多相关《实验报告六ADONET中的数据绑定Word文档格式.docx(15页珍藏版)》请在冰豆网上搜索。
(2)源代码:
Student数据库:
GridView.aspx:
<
formid="
form1"
runat="
server"
>
<
div>
asp:
GridViewID="
GridView1"
AllowPaging="
True"
ondatabound="
GridView1_DataBound"
onpageindexchanging="
GridView1_PageIndexChanging"
PageSize="
5"
PagerSettingsMode="
NextPrevious"
NextPageText="
下一页&
amp;
gt;
"
PreviousPageText="
前一页&
lt;
/>
/asp:
GridView>
LabelID="
Label1"
Text="
Label"
Label>
&
nbsp;
Label2"
br/>
Label3"
/div>
/form>
GridView.aspx.cs:
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!
Page.IsPostBack)bindgrid();
}
voidbindgrid()
stringsqlconnstr=ConfigurationManager.ConnectionStrings["
connectionstring"
].ConnectionString;
DataSetds=newDataSet();
using(SqlConnectionsqlconn=newSqlConnection(sqlconnstr))
SqlDataAdaptersqld=newSqlDataAdapter("
selectno,name,birth,addressfromstudent"
sqlconn);
sqld.Fill(ds,"
tabstudent"
);
GridView1.DataSource=ds.Tables["
].DefaultView;
GridView1.DataBind();
protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse)
GridView1.PageIndex=e.NewPageIndex;
bindgrid();
protectedvoidGridView1_DataBound(objectsender,EventArgse)
Label1.Text="
共"
+(GridView1.PageCount).ToString()+"
页"
;
Label2.Text="
第"
+(GridView1.PageIndex+1).ToString()+"
Label3.Text=string.Format("
总页数:
{0},当前页:
{1}"
GridView1.PageCount,GridView1.PageIndex+1);
}
Datalist.aspx:
DataListID="
DataList1"
RepeatDirection="
Horizontal"
RepeatColumns="
3"
ItemTemplate>
tablestyle="
width:
100%;
tr>
tdwidth="
40%"
学号"
Width="
100%"
/td>
60%"
Text='
%#Eval("
no"
)%>
'
/tr>
姓名"
Label4"
name"
Label5"
出生日期"
Label6"
birth"
Label7"
地址"
Label8"
address"
/table>
/ItemTemplate>
DataList>
LinkButtonID="
LinkButton1"
onclick="
LinkButton1_Click"
上一页<
LinkButton>
LinkButton2"
LinkButton2_Click"
下一页<
当前页:
Label9"
Datalist.aspx.cs:
Page.IsPostBack)
Label9.Text="
1"
listbind();
voidlistbind()
intpag=Convert.ToInt32(Label9.Text);
select*fromstudent"
PagedDataSourceps=newPagedDataSource();
ps.DataSource=ds.Tables["
ps.AllowPaging=true;
ps.PageSize=1;
ps.CurrentPageIndex=pag;
if(pag==1)
LinkButton1.Enabled=false;
else
LinkButton1.Enabled=true;
if(pag==ps.PageCount)
LinkButton2.Enabled=false;
DataList1.DataSource=ps;
DataList1.DataBind();
protectedvoidLinkButton1_Click(objectsender,EventArgse)
Label9.Text=Convert.ToString(Convert.ToInt32(Label9.Text)-1);
protectedvoidLinkButton2_Click(objectsender,EventArgse)
Label9.Text=Convert.ToString(Convert.ToInt32(Label9.Text)+1);
FormView.aspx:
FormViewID="
FormView1"
CellPadding="
4"
DataKeyNames="
ForeColor="
#333333"
231px"
DataSourceID="
SqlDataSource1"
NextPreviousFirstLast"
上一页&
EditItemTemplate>
Width="
TextBoxID="
noTextBox"
Text='
%#Bind("
TextBox>
nameTextBox"
Label10"
birthTextBox"
Label11"
addressTextBox"
align="
center"
updateButton"
CommandName="
Update"
更新<
updatecancelButton1"
Cancel"
取消<
/EditItemTemplate>
InsertItemTemplate>
Label12"
>
insertButton"
Insert"
插入<
insertcancelButton"
CausesValidation="
False"
/InsertItemTemplate>
noLabel1"
%#Eval("
)%>
right"
newButton"
new"
新建<
editButton"
edit"
更新"
deleteButton"
Delete"
删除<
HeaderTemplate>
学生详细信息
/HeaderTemplate>
FormView>
SqlDataSourceID="
ConnectionString="
DataSource=PC-200903151039;
InitialCatalog=student;
IntegratedSecurity=True"
InsertCommand="
insertintostudent(no,name,birth,address)values(@no,@name,@birth,@address)"
ProviderName="
System.Data.SqlClient"
SelectCommand="
SELECT[No],[Name],[birth],[Address]FROM[student]"
DeleteCommand="
deletefromstudentwhereno=@no"
UpdateCommand="
updatestudentsetname=@name,birth=@birth,address=@addresswhereno=@no"
SqlDataSource>
(3)实验结果
GridView分页的结果:
Datalist分页的结果:
FormView的结果:
实验总结(结论或问题分析):
通过这次实验我学会了数据绑定,熟悉了GridView、DataList和FormView进行数据显示和处理的方法。
实验成绩
任课教师签名
郭俊恩
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 报告 ADONET 中的 数据 绑定