【问题标题】:Comparing Cell value of gridview with textbox value将gridview的单元格值与文本框值进行比较
【发布时间】:2012-06-07 06:10:57
【问题描述】:

我有一个 6 列的网格视图 (SAPUserID ,SAPDescription,SAPPassword,OSUserID,OSDescription,OSPassword)CHANGE PASSWORD 按钮。单击此按钮后,网格视图下方的面板 (pnlChangePwd) 变为可见,其中包含 3 个文本框(User ID, New Password, Confirm Password) 和一个 Save 按钮。目前,如果我输入与旧密码相同的新密码,它会接受。如何将txtNewPassword 中的值与网格视图中 SAPPassword 或 OSPassword 的单元格值进行比较?

注意:根据用户想要的数据(SAP 或操作系统),一次只能看到 3 列

网格视图代码:

<asp:GridView runat="server" ID="gvPassInfo" AutoGenerateColumns="false" 
                          CellPadding="4" ForeColor="#333333" GridLines="Both" DataKeyNames="user_id" 
                          CssClass="Gridview"  OnRowEditing="gvPassInfo_RowEditing"
                          OnRowCommand="gvPassInfo_RowCommand"  OnRowDataBound="gvPassInfo_RowDataBound">
                <RowStyle BackColor="#EFF3FB" />
                <Columns>                                       
                    <asp:TemplateField HeaderText="User ID" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblSAPUserId" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="User ID" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblOSUserId" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Description" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblSAPDescription" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Description" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblOSDescription" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Password" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblSAPPassword" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Password" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblOSPassword" runat="server">
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Change Password">
                        <ItemTemplate>
                            <asp:ImageButton ID="ImgBtnChangePass" runat="server" ImageUrl="~/images/PW.jpg" CausesValidation="false"
                                             CommandName="Edit" />
                        </ItemTemplate>
                    </asp:TemplateField>


                </Columns>
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>

【问题讨论】:

  • 网格中是否只有一行
  • 请检查我编辑的问题...不确定网格视图中的行。
  • 你能在你的 aspx 页面上包含 griview 的标记吗?
  • 查看我编辑的问题..

标签: c# asp.net


【解决方案1】:

这是保存按钮的代码

    var currentRow = gvPassInfo.Rows.OfType<GridViewRow>().Single(r => ((Label)r.FindControl("lblSAPUserId")).Text == txtUserId.Text);
    bool doesMatch = ((Label)currentRow.FindControl("lblOSPassword")).Text == "NewPassword";

但是最好在你绑定到网格的集合中搜索密码。

【讨论】:

  • 是的,每一行都有图像按钮。当您单击任何按钮时,用户 ID 将被复制到 txtUserId 字段中。
  • 问题已解决:) juz 将执行的查询保存在一个字符串变量中,并将其与文本框值进行比较..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多