2012-06-13 41 views
0

我有問題,當我嘗試從ImageButton傳遞值到控件參數,那麼更新命令可以從控制參數中檢索值來執行更新語句。如何使用ImageButton傳遞值來更新數據庫?

我想要傳遞值當點擊ImageButton APPROVE時Status = 1,否則當點擊ImageButton REJECT時傳遞值Status = 2。

在哪裏以及如何分配值狀態? 當我運行我的代碼時,我收到此錯誤:必須聲明標量變量「@Status」。

或任何建議傳遞值狀態?

我的ImageButton:

<ItemTemplate> 
<asp:ImageButton runat="server" ID="APPROVE" CommandName="update" 
ImageUrl="~/images/accept.png" 
OnClientClick="if (!window.confirm('Are you sure you want to approve this booking?')) return false;" /> 
</ItemTemplate> 


<ItemTemplate> 
<asp:ImageButton runat="server" ID="REJECT" CommandName="update" 
ImageUrl="~/images/reject.png" 
OnClientClick="if (!window.confirm('Are you sure you want to reject this booking?')) return false;" /> 
</ItemTemplate> 

我的UPDATE語句

UpdateCommand="UPDATE [bookingschedule] SET [email protected] WHERE [bookingScheduleID] = @bookingScheduleID" 

我ControlParameter

<UpdateParameters>        
<asp:Parameter Name="bookingScheduleID" Type="Int32" /> 
<asp:ControlParameter Name="Status" ControlID="APPROVE" Type="Int32" /> 
<asp:ControlParameter Name="Status" ControlID="REJECT" Type="Int32" /> 
</UpdateParameters> 

回答

0

A鍵沒有在HTML中具有價值,因此你不能用它在ControlParameter聲明中。一種解決方案是在窗體上創建一個隱藏文本框。讓我們稱之爲「StatusType」。

<input type="hidden" name="StatusType" value="0"> 

現在,在每個按鈕的「OnClientClick」中,將StatusType的值分配給1或2(或任何您定義的狀態碼)。

OnClientClick="if (!window.confirm('Are you sure you want to reject this booking?')) { 
    return; 
} 
else { 
    $('#StatusType').val(0); 
}" 

然後使用ControlParameter中的「StatusType」。

<asp:ControlParameter Name="Status" ControlID="StatusType" Type="Int32" /> 
0

您是否嘗試過使用的ImageButton的CommandArgument property

從MSDN:

有時候,多的ImageButton控件有關,並共享相同的值CommandName屬性,如排序。使用此屬性來補充CommandName屬性,並提供有關要執行的命令的附加信息,例如Ascending。 CommandName和CommandArgument屬性的值通常用於OnCommand事件處理程序中,以確定單擊ImageButton控件時要執行的操作。

<asp:ImageButton id="imagebutton1" runat="server" 
     AlternateText="Sort Ascending" 
     ImageUrl="images/pict.jpg" 
     OnCommand="ImageButton_Command" 
     CommandName="Sort" 
     CommandArgument="Ascending"/> 
+0

我沒有嘗試這個和其他的解決方案,只是我總是收到錯誤:必須聲明標量變量「@Status」 看起來價值不只是路過 – mcheng

相關問題