怎样给DetailsView控件中的一个字段赋值?
DetailsView控件的代码如下, 我想给 "序号 "字段赋一个值,例如 "00001 ",
请问应该写在哪个事件里面? 具体代码怎么写?
我尝试了写在好几个事件里面,都不行,求助!!
<asp:DetailsView ID= "DetailsView1 " runat= "server " AutoGenerateRows= "False " DataKeyNames= "Id "
DataSourceID= "AccessDataSource1 " PageIndex= "1 " Height= "92px " Width= "293px "
AutoGenerateEditButton= "True " AutoGenerateInsertButton= "True " HorizontalAlign= "Left " OnDataBound= "DetailsView1_DataBound " >
<Fields>
<asp:TemplateField HeaderText= "序号: " SortExpression= "Id ">
<EditItemTemplate>
<asp:Label ID= "Label1 " runat= "server " Text= ' <%# bind( "Id ") %> '> </asp:Label>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID= "TextBox1 " runat= "server " Text= ' <%# Bind( "Id ") %> '> </asp:TextBox>
</InsertItemTemplate>
<HeaderStyle Font-Bold= "True " HorizontalAlign= "Right " Width= "100px " />
<ItemTemplate>
<asp:Label ID= "Label1 " runat= "server " Text= ' <%# Bind( "Id ") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "Projectname " HeaderText= "项目名称: " SortExpression= "Projectname " >
<ItemStyle HorizontalAlign= "Left " Font-Bold= "True " />
<HeaderStyle HorizontalAlign= "Right " Width= "100px " />
</asp:BoundField>
<asp:BoundField DataField= "Remark " HeaderText= "备注: " SortExpression= "Remark " >
<HeaderStyle HorizontalAlign= "Right " Width= "100px " Font-Bold= "True " />
</asp:BoundField>
<asp:TemplateField ShowHeader=False>
<ItemTemplate>
<asp:LinkButton ID= "linkbutton1 " runat=server
OnClientClick= "javascript:return confirm( '你确认要删除吗? ') " CausesValidation= "False "
CommandName= "Delete " Text= "删除 "> </asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign= "Right " />
</asp:TemplateField>
</Fields>
<CommandRowStyle HorizontalAlign= "Right " />
<EmptyDataTemplate>
<asp:DetailsView ID= "DetailsVew2 " runat= "server " AutoGenerateRows= "False "
DataKeyNames= "Id " DataSourceID= "AccessDataSource1 " PageIndex= "1 " Height= "92px " Width= "293px "
AutoGenerateInsertButton= "True " HorizontalAlign= "Left " DefaultMode= "Insert " >
<Fields>
<asp:BoundField DataField= "Id " HeaderText= "序号: " ReadOnly= "True " SortExpression= "Id " >
<HeaderStyle HorizontalAlign= "Right " Width= "100px " Font-Bold= "True " />
</asp:BoundField>
<asp:BoundField DataField= "Projectname " HeaderText= "项目名称: " SortExpression= "Projectname " >
<ItemStyle HorizontalAlign= "Left " Font-Bold= "True " />
<HeaderStyle HorizontalAlign= "Right " Width= "100px " Font-Bold= "True " />
</asp:BoundField>
<asp:BoundField DataField= "Remark " HeaderText= "备注: " SortExpression= "Remark " >
<HeaderStyle HorizontalAlign= "Right " Width= "100px " Font-Bold= "True " />
</asp:BoundField>
</Fields>
<CommandRowStyle HorizontalAlign= "Right " />
</asp:DetailsView>
</EmptyDataTemplate>
</asp:DetailsView>
[解决办法]
protected void Page_Load(object sender, EventArgs e) { this.DetailsView1.Rows[0].Cells[1].Text = "haha "; }
[解决办法]
((Label)DetailsView.Rows[0].FindContral( "放数据的控件的ID ")).Text= "你想要的值 ";
用for循环可以遍历Row