更新的GridView与图片按钮 [英] Update Gridview with Image Button

查看:157
本文介绍了更新的GridView与图片按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2图像按钮,接受和拒绝。
接受按钮更新[状态] 1
拒绝按钮更新[状态] 2

我已经成功地使用更新命令来更新接受按钮

 更新命令=UPDATE [bookingschedule]设置状态='1'WHERE [bookingScheduleID] = @bookingScheduleID

不过,我不知道如何设置更新命令拒绝按钮,因为我可以宣布更新命令只有一次。

  UpdateCommand2 =UPDATE [bookingschedule]设置状态='2'WHERE [bookingScheduleID] = @bookingScheduleID(不正确)

我应该怎么做才能让拒绝按钮的功能?我应该在哪里把这个月2日更新命令行:

 更新命令=UPDATE [bookingschedule]设置状态='2'WHERE [bookingScheduleID] = @bookingScheduleID

我做的这一切在编码客户端:

接受按钮:

 < ASP:的TemplateField的HeaderText =行动批准>
<&ItemTemplate中GT;
< ASP:ImageButton的=服务器ID =更新命令
  的CommandName =更新的ImageUrl =〜/图片/ accept.png
  的OnClientClick =如果返回false(window.confirm('您确定要批准此预订?')!); />
< / ItemTemplate中>
< / ASP:的TemplateField>

拒绝按钮:

 < ASP:的TemplateField的HeaderText =行动拒绝>
<&ItemTemplate中GT;
< ASP:ImageButton的=服务器ID =更新命令的CommandName =更新的OnClick =拒绝
  的ImageUrl =〜/图片/ reject.png
  的OnClientClick =如果返回false(window.confirm('您确定要拒绝这个预订?')!); />
< / ItemTemplate中>
< / ASP:的TemplateField>

SQL数据源:

 < ASP:SqlDataSource的ID =SqlDataSource1=服务器的ConnectionString =<%$的ConnectionStrings:ConnectionString1%>中
            的SelectCommand =SELECT [bookingScheduleID],[EVENTTITLE],[week1],[week2],[译员更加],[week4],[week5],[week6],[week7],[week8],[exhibitorname],[boothAlias ],[类别],[状态],[行事历],[custNo] FROM [booking_all]
            更新命令=UPDATE [bookingschedule]设置状态='1'WHERE [bookingScheduleID] = @bookingScheduleID
            >
        < / ASP:SqlDataSource的>
        < UpdateParameters>
        < ASP:参数名称=bookingScheduleIDTYPE =的Int32/>
        < / UpdateParameters>


解决方案

使用控制动态存储/转发状态的基础上的按钮点击

 更新命令=UPDATE [bookingschedule]设置状态= @状态WHERE [bookingScheduleID] = @bookingScheduleID

然后添加

 < ASP:ControlParameter名称=状态控件ID =StatusSelectionControl属性名=TEXT类型=的Int32/>

在propertyName的应该是相对于所使用的控制 - 我假设文本框,但你也可以使用隐藏域

I have 2 image buttons, Accept and Reject. Accept button will update [status] to 1 Reject button will update [status] to 2

I had successfully use UpdateCommand to update Accept button

UpdateCommand="UPDATE [bookingschedule] SET status='1'WHERE [bookingScheduleID] = @bookingScheduleID"

But, I do not know how to set update command for Reject button since I can declared UpdateCommand once only.

UpdateCommand2="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID" (incorrect)

What should I do to make Reject button function? Where should i put this 2nd update command line:

UpdateCommand="UPDATE [bookingschedule] SET status='2'WHERE [bookingScheduleID] = @bookingScheduleID"

I do all this coding at client side:

Accept Button:

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

Reject Button:

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

SQL datasource:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
            SelectCommand="SELECT [bookingScheduleID], [eventTitle], [week1], [week2], [week3], [week4], [week5], [week6], [week7], [week8], [exhibitorname], [boothAlias], [category], [status], [dateBook],[custNo] FROM [booking_all]" 
            UpdateCommand="UPDATE [bookingschedule] SET status='1'WHERE [bookingScheduleID] = @bookingScheduleID"
            >
        </asp:SqlDataSource>
        <UpdateParameters>
        <asp:Parameter Name="bookingScheduleID" Type="Int32" />
        </UpdateParameters> 

解决方案

Use a control to dynamically store/pass the status based on the button clicked

UpdateCommand="UPDATE [bookingschedule] SET status=@Status WHERE [bookingScheduleID] = @bookingScheduleID"

then add

<asp:ControlParameter Name="Status" ControlID="StatusSelectionControl" PropertyName="Text" Type="Int32" />

the propertyName should be relative to the control used - am assuming TextBox, but you can also use hidden field

这篇关于更新的GridView与图片按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆