.Net 后台获取GridView里<TemplateField>的控件值是否变化

来源:互联网 发布:淘宝apple store优惠券 编辑:程序博客网 时间:2024/05/18 13:27

用遍历的方法即可获得

通过Label标签来监视是否发生变化



List.aspx:(有一个TextBox文本框和Label标签)

<asp:TemplateField HeaderText="优">
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td width="62px" height="50px" align="center" style="border:solid #333333; border-width:0px 0px 1px 0px">
                                    <%# GetGradeRange1(Container.DataItem) %>
                                </td>
                                </tr>
                            <tr>
                                <td width="62px" height="57px" align="center" class="grade">                //从这里开始
                                   <asp:Label ID="Lb_1" runat="server" Text='<%# GetGrade1(Container.DataItem) %>' Visible="false"></asp:Label>
                                   <asp:TextBox ID="TxtBox_1" runat="server" Text= '<%# GetGrade1(Container.DataItem) %>' Width="20px" ForeColor="Red" onkeyup="value=value.replace(/[^\d]/g,'')" ></asp:TextBox>    
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    

                </asp:TemplateField>


List.aspx.cs:


foreach (GridViewRow row in GVGuideTecherCheck.Rows)                //遍历每一行
            {
                Lb_flag = row.FindControl("Lb_1") as Label;                          //每一行的控件
                Txt_flag = row.FindControl("TxtBox_1") as TextBox;
                if (Lb_flag.Text != Txt_flag.Text && Txt_flag.Text != "")             //因为Label不能变 只有TextBox的值变了 所以Label可以监视TextBox
                {

                    //进行你想要的数据库操作

                }

            }

0 0
原创粉丝点击