当用户单击除更新和取消之外的其他链接时移出gridview时的警报消息 [英] Alert Message when user moves out of gridview when he clicks other links apart from update and cancel

查看:88
本文介绍了当用户单击除更新和取消之外的其他链接时移出gridview时的警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了gridveiw的问题。我的gridveiw有一些'n'行和几列。当用户单击编辑时,单击gridview单元格即可编辑。现在我需要的是,如果用户在我的情况下导航我在左侧有树视图,如果用户点击而没有点击我的gridview中的取消或更新按钮,只需点击链接从树视图左侧,它应该提示消息你可能会丢失行中未保存的数据我如何实现这个



以下是我的网格代码



I am facing a problem with gridveiw. My gridveiw has some 'n' number of rows and few columns. When user clicks on edit click the gridview cells becomes editable. Now what I need is if user navigates in my case i have treeview on left hand side which has several pages listed in treeview format if user click without clicking the "cancel" or "update" button in my gridview and just clicks the links from the left hand side from tree view it should prompt message saying "You might loose the unsaved data in your row" How do i implement this

Below is my gridveiw Code

<asp:GridView ID="gvTestScriptComponent" runat="Server" CssClass="GridViewStyle" AutoGenerateColumns="False"
       CellPadding="4" ForeColor="Black" DataKeyNames="ComponentID"
       ShowFooter="true" Height="110px" Style="margin-right: 0px" Width="990px" BackColor="White"
       OnRowDataBound="gvTestScriptComponent_RowDataBound" AutoGenerateEditButton="True"
       OnRowEditing="gvTestScriptComponent_RowEditing" OnRowCancelingEdit="gvTestScriptComponent_RowCancelingEdit"
       OnRowUpdating="gvTestScriptComponent_RowUpdating" OnRowDeleted="gvTestScriptComponent_RowDeleted"
       BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
       OnRowCommand="gvTestScriptComponent_RowCommand">
       <Columns>
           <asp:TemplateField HeaderText="ComponentID" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblComponentID" runat="server" Height="20px" Text='<%#Eval("ComponentID")%>'>  </asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Center"></ItemStyle>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Options" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="images/delete.ico" CausesValidation="false"
                       CommandName="DeleteRow" OnClick="btnDelete_Click"  OnClientClick='return confirm("Are you sure you want to delete?");'  />
               </ItemTemplate>
               <FooterTemplate>
                   <asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
                       CommandName="SaveRow" OnClick="btnSave_Click" />
               </FooterTemplate>
               <ItemStyle HorizontalAlign="Center"></ItemStyle>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="TestWindow/Frame Name" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblTestWindow" runat="server" Height="20px" Text='<%#Eval("BrowserPage")%>'>  </asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:DropDownList ID="ddlTestWindow" runat="server" Visible="true" AutoPostBack="True"
                       OnSelectedIndexChanged="ddlTestWindow_SelectedIndexChanged">
                   </asp:DropDownList>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:DropDownList ID="ddlFooterTestWindow" runat="server" Visible="true" AutoPostBack="True"
                       OnSelectedIndexChanged="ddlFooterTestWindow_SelectedIndexChanged">
                   </asp:DropDownList>
               </FooterTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Test Object" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblTestObject" runat="server" Height="20px" Text='<%#Eval("ObjectName")%>'>  </asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:DropDownList ID="ddlTestObject" runat="server" Visible="true" AutoPostBack="True"
                       OnSelectedIndexChanged="ddlTestObject_SelectedIndexChanged" >
                   </asp:DropDownList>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:DropDownList ID="ddlFooterTestObject" runat="server" Visible="true" AutoPostBack="True"
                       OnSelectedIndexChanged="ddlFooterTestObject_SelectedIndexChanged">
                   </asp:DropDownList>
               </FooterTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Test Operation" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblTestOperation" runat="server" Height="20px" Text='<%#Eval("Action")%>'></asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:DropDownList ID="ddlTestOperation" runat="server" Visible="true">
                   </asp:DropDownList>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:DropDownList ID="ddlFooterTestOperation" runat="server" Visible="true">
                   </asp:DropDownList>
               </FooterTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Test Data" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblTestData" runat="server" Height="20px" Text='<%#Eval("TestData")%>'></asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:TextBox ID="txtTestData" runat="server" Text='<%# Bind("TestData") %>' Visible="true">
                   </asp:TextBox>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:TextBox ID="txtFooterTestData" runat="server" Visible="true"></asp:TextBox>
               </FooterTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Reusable‎OutputData" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblReUseableOutputData" runat="server" Height="20px" Text='<%#Eval("ReUsableOutputData")%>'></asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:TextBox ID="txtReUseableOutputData" runat="server" Text='<%# Bind("ReUsableOutputData") %>'
                       Visible="true">
                   </asp:TextBox>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:TextBox ID="txtFooterReUseableOutputData" runat="server" Visible="true"></asp:TextBox>
               </FooterTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="Step Description" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
                   <asp:Label ID="lblStepDescription" runat="server" Height="20px" Text='<%#Eval("Steps")%>'></asp:Label>
               </ItemTemplate>
               <ItemStyle HorizontalAlign="Left"></ItemStyle>
               <EditItemTemplate>
                   <asp:TextBox ID="txtStepDescription" runat="server" Text='<%# Bind("Steps") %>' Visible="true">
                   </asp:TextBox>
               </EditItemTemplate>
               <FooterTemplate>
                   <asp:TextBox ID="txtFooterStepDescription" runat="server" Visible="true"></asp:TextBox>
               </FooterTemplate>
           </asp:TemplateField>
       </Columns>
       <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
       <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
       <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
       <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" HorizontalAlign="Justify"
           VerticalAlign="Middle" />
       <SortedAscendingCellStyle BackColor="#F7F7F7" />
       <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
       <SortedDescendingCellStyle BackColor="#E5E5E5" />
       <SortedDescendingHeaderStyle BackColor="#242121" />
       <EmptyDataTemplate>
           <table>
               <tr style="background-color: #999999;">
                   <th>
                       Option
                   </th>
                   <th>
                       Test Window
                   </th>
                   <th>
                       Test Object
                   </th>
                   <th>
                       Test Operation
                   </th>
                   <th>
                       Test Data
                   </th>
                   <th>
                       ReUseableOutputData
                   </th>
                   <th>
                       StepDescription
                   </th>
               </tr>
               <tr>
                   <td headers="Option">
                       <asp:ImageButton ID="btnSave" runat="server" ImageUrl="images/save.ico" CausesValidation="false"
                           CommandName="FirstSaveRow" OnClick="btnSave_Click" />
                   </td>
                   <td headers="Test Window">
                       <asp:DropDownList ID="ddlFooterTestWindow" runat="server" Visible="true" AutoPostBack="True"
                           OnSelectedIndexChanged="ddlFooterTestWindow_SelectedIndexChanged">
                       </asp:DropDownList>
                   </td>
                   <td headers="Test Object">
                       <asp:DropDownList ID="ddlFooterTestObject" runat="server" Visible="true" AutoPostBack="True"
                           OnSelectedIndexChanged="ddlFooterTestObject_SelectedIndexChanged">
                       </asp:DropDownList>
                   </td>
                   <td headers="Test Operation">
                       <asp:DropDownList ID="ddlFooterTestOperation" runat="server" Visible="true">
                       </asp:DropDownList>
                   </td>
                   <td headers="Test Data">
                       <asp:TextBox ID="txtFooterTestData" runat="server" Visible="true"></asp:TextBox>
                   </td>
                   <td headers="ReUseableOutputData">
                       <asp:TextBox ID="txtFooterReUseableOutputData" runat="server" Visible="true"></asp:TextBox>
                   </td>
                   <td headers="StepDescription">
                       <asp:TextBox ID="txtFooterStepDescription" runat="server" Visible="true"></asp:TextBox>
                   </td>
               </tr>
           </table>
       </EmptyDataTemplate>
   </asp:GridView>

推荐答案

Hi Shaham,



This is tricky and nice question, you can implement some tricky solution to overcome the issue ;-)

Earlier in previous project I came across the same kind of requirement, my goodness we use JQuery in that project.

Here is What I have done



1) Set some flag variable(Ex: isEditClicked) to true when user clicks on edit row option.

2) Now If user clicks on Update button(on success) or Cancel button change is EditClicked = false so that it ensures that edit is complete/Cancelled.

3) Check the value isEditClicked whenever user tend to click on other links, if its true then alert user that yet to save pending changes or something otherwise do that link process.




Hope this helps you a bit.



Regards,

RK
Hi Shaham,

This is tricky and nice question, you can implement some tricky solution to overcome the issue ;-)
Earlier in previous project I came across the same kind of requirement, my goodness we use JQuery in that project.
Here is What I have done

1) Set some flag variable(Ex: isEditClicked) to true when user clicks on edit row option.
2) Now If user clicks on Update button(on success) or Cancel button change isEditClicked = false so that it ensures that edit is complete/Cancelled.
3) Check the value isEditClicked whenever user tend to click on other links, if its true then alert user that yet to save pending changes or something otherwise do that link process.


Hope this helps you a bit.

Regards,
RK


这篇关于当用户单击除更新和取消之外的其他链接时移出gridview时的警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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