2012-06-13 3 views
0

ImageButton에서 controlparameter로 값을 전달하려고 할 때 문제가 발생하면 update 명령은 update 문을 실행하기 위해 컨트롤 매개 변수에서 값을 검색 할 수 있습니다.ImageButton을 사용하여 값을 전달하여 데이터베이스를 업데이트하는 방법은 무엇입니까?

ImageButton을 클릭하면 값 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" 

A 버튼을 HTML에 값을 가지고 있지 않으며, 따라서 당신이 그것을 사용할 수 없습니다

<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

내 ControlParameter 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 및 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

관련 문제