2012-11-08 51 views
1

錯誤信息單擊編輯時:錯誤的GridView

變量名「@Bitnet」已聲明。變量名稱在查詢批處理或存儲過程中必須是唯一的。當試圖編輯gridview。

我希望能夠更新複選框字段。這個gridview基於表連接。

<asp:Content ID="Content4" runat="server" contentplaceholderid="ContentPlaceHolder2"> 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="INST_ID,BITNET" DataSourceID="SqlDataSource1" AllowPaging="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"> 
    <Columns> 
     <asp:CommandField ShowEditButton="True" /> 
     <asp:BoundField DataField="INST_ID" HeaderText="INST_ID" ReadOnly="True" SortExpression="INST_ID" /> 
     <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> 
     <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> 
     <asp:BoundField DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" /> 
     <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> 
     <asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1" /> 
     <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> 
     <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" /> 
     <asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" /> 
     <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" /> 
     <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /> 
     <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" /> 
     <asp:BoundField DataField="BITNET" HeaderText="BITNET" ReadOnly="True" SortExpression="BITNET" /> 
     <asp:TemplateField HeaderText="Active"> 
      <ItemTemplate> 
       <asp:CheckBox ID="Active" runat="server" Checked='<%# Eval("Active").ToString() == "1" ? true:false %>' Enabled="false" /> 
      </ItemTemplate> 
      <EditItemTemplate> 
       <asp:CheckBox ID="Active" runat="server" Checked="true" Enabled="false" /> 
      </EditItemTemplate> 
     </asp:TemplateField> 

    </Columns> 
</asp:GridView> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPLOGINConnectionString %>" SelectCommand="SELECT IALO.INST_ID, IALO.FirstName, IALO.LastName, IALO.Prefix, IALO.Title, IALO.Address1, IALO.City, IALO.State, IALO.Zip, IALO.Country, IALO.Phone, IALO.Fax, IALO.BITNET, IALO.Active FROM CEOTable INNER JOIN IALO ON CEOTable.Inst_ID = IALO.INST_ID WHERE (CEOTable.Bitnet = @Bitnet)"> 
    </asp:SqlDataSource> 
+0

你在select中使用@Bitnet,你從哪裏得到那個值? – Aristos

回答

1

我解決我自己的問題的問題是我沒有清理我的第一個參數保護 無效的Page_Load(對象發件人,EventArgs的){ SqlDataSource1.SelectParameters.Clear(); }

現在解決了它正常工作的問題。

1

您必須先聲明參數。那麼只有你可以使用它。它應該是這樣的

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPLOGINConnectionString %>" SelectCommand="SELECT IALO.INST_ID, IALO.FirstName, IALO.LastName, IALO.Prefix, IALO.Title, IALO.Address1, IALO.City, IALO.State, IALO.Zip, IALO.Country, IALO.Phone, IALO.Fax, IALO.BITNET, IALO.Active FROM CEOTable INNER JOIN IALO ON CEOTable.Inst_ID = IALO.INST_ID WHERE (CEOTable.Bitnet = @Bitnet)"> 
<SelectParameters> 
    <asp:Parameter Name="Bitnet" Type="Int32" DefaultValue="0" /> 
</SelectParameters> 
<UpdateParameters> 
    <asp:Parameter Name="Bitnet" Type="Int32" DefaultValue="0" /> 
</UpdateParameters> 
      </asp:SqlDataSource>