如何在C#中验证datagridview单元 [英] how to validate datagridview cell in C#

查看:74
本文介绍了如何在C#中验证datagridview单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格视图,其中包含两列........

就像


日期日期
2005年1月1日,星期一
2005年7月1日,星期一
2005年1月14日,星期一
2005年1月21日,星期一
2005年1月28日,星期一
2005年5月2日,星期一
2005年12月2日,星期一
2005年2月19日,星期一
2005年2月26日,星期一

我想以一种可以更改日期的方式验证用户(让他更改日期(2005年7月1日),但不能小于或等于2005年1月1日且不大于或等于2005年1月14日
请朋友,如果您有任何想法请帮助我.....

在高级感谢
lakhan

i have a data grid view which contain two columns...........

like


date day
1/1/2005 Monday
7/1/2005 Monday
14/1/2005 Monday
21/1/2005 Monday
28/1/2005 Monday
5/2/2005 Monday
12/2/2005 Monday
19/2/2005 Monday
26/2/2005 Monday

i want to validate user in such way that he can change date(let 7/1/2005 )but not less or = than 1/1/2005 and not more than or =14/1/2005
please friend if u have any idea please help me.....

thanks in advanced
lakhan

推荐答案

您可以在文本框文本更改事件上调用JavaScript函数...

http://stackoverflow.com/Questions/73971/using-javascript-how-do-i-make-sure-a-date-range-is-valid [
you can call a javascript function on text box text change event...

http://stackoverflow.com/questions/73971/using-javascript-how-do-i-make-sure-a-date-range-is-valid[^]


您需要使用 CellValidating 事件来验证datagridview的任何单元格.

试试这些:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx [ ^ ]


http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx [ ^ ]

希望对您有所帮助:)
You need to use CellValidating event to validate any cell of datagridview.

Try these:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx[^]


http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx[^]

hope it helps :)


这可能对您有所帮助,请参考以下链接:

http://www.daniweb.com/web-development/aspnet/threads/167024 [ ^ ]


ASP.NET语法(切换纯文本)
This could be help you for more details refer the following link:

http://www.daniweb.com/web-development/aspnet/threads/167024[^]


ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="OperationSheetMultipleArticle.aspx.vb" Inherits="OperationSheetMultipleArticle" EnableSessionState="true" %>
<%@ OutputCache Location="Client" duration="5" varybyparam="none" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<script type="text/javascript" language=javascript>
function keyDownNumber()
{ 
    var key;    
    if(navigator.appName == 'Microsoft Internet Explorer')
        key = event.keyCode;
    else
        key = event.which
 
    if ( !(key >= 48 && key <= 57) && key != 8 && key != 46 && key != 36 && key != 37)
    {
        event.returnValue = false;        
    }
}
</script>
<head  runat="server">
    <title>Operation Sheet</title> 
</head>
<body leftmargin=5 topmargin=3> 
    <form id="form1"  runat="server">
 <asp:GridView ID="GVDetail" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="LightGray"

          BorderColor="White" BorderStyle="Ridge" BorderWidth="1px" CaptionAlign="Top" CellPadding="0" Font-Size="12px" Font-Strikeout="False" Font-Underline="False" Height="1px" HorizontalAlign="Left" Style="left: 4px; top: 127px" UpdateAfterCallBack="True" Width="100%"  EmptyDataText="NO RECORD FOUND" PageSize="12">
                    <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" Font-Italic="False" Font-Underline="False"

                        ForeColor="#E7E7FF" />
                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                    <Columns>
                     <asp:templatefield headertext="Del."  >
                            <itemstyle borderstyle="None" font-size="8pt" width="10px" horizontalalign="Center" />
                            <headerstyle font-bold="False" width="10px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:CheckBox id="ChkDelete" runat="server" width="20px"  ></asp:CheckBox>                                                                   
                            </itemtemplate>
                        </asp:templatefield>                         
                         <asp:templatefield headertext="Article No.">
                            <itemstyle borderstyle="None" font-size="8pt" width="20px" />
                            <headerstyle font-bold="False" width="65px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:TextBox id="TxtArticleNo" readonly=true text='<% # eval("ArticleNo") %>' runat="server" width="65px" borderstyle="None" font-size="8pt" BackColor="LightCyan" autocallback=true></asp:TextBox>                                                                                                              
                        </itemtemplate>
                        </asp:templatefield>                         
                        <asp:templatefield headertext="Amount">
                            <itemstyle borderstyle="None" font-size="8pt" width="20px" />
                            <headerstyle font-bold="False" width="65px" font-size="8pt"/>
                            <itemtemplate>
                                <asp:TextBox id="Amount" text='<% # eval("Amount") %>' runat="server" width="65px" borderstyle="None" font-size="8pt" onkeypress="keyDownNumber()"  BackColor="Beige"></asp:TextBox>                                                                                 
                        </itemtemplate>
                        </asp:templatefield>                                                  
                    </Columns>
                    <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
             <AlternatingRowStyle BackColor="LightGray" />
                </asp:GridView>   
</form>
</body>
</html>


这篇关于如何在C#中验证datagridview单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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