如何在asp.net的详细信息视图中设置面板默认按钮?

时间:2009-03-31 06:19:09

标签: asp.net detailsview defaultbutton

<asp:panel ID="Panel1"  runat="server">

<asp:DetailsView ID="DetailsView1"

....

<asp:templatefield ShowHeader="False">

<insertitemtemplate>

<asp:Button ID="btnAdd" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:Button>

...
<asp:DetailsView>
</asp:panel>

and i write the code for setting the panels default button in details view's DataBound event

Button btnAdd = new Button();
  btnAdd = DetailsView1.Rows[indexNumber].FindControl("btnAdd") as Button;
  Panel1.DefaultButton = btnAdd.UniqueID;

but I get the error :
The DefaultButton of 'Panel1' must be the ID of a 
control of type IButtonControl. 

1 个答案:

答案 0 :(得分:-1)

在ASP中,您将ID设置为

ID="BtnAdd"

在代码中使用

FindControl("btnAdd")

btnAdd区分大小写我相信