简体   繁体   中英

Calendar in gridview edit mode

I have a gridview connected to database using sqldatasource. There is a datetime field in the gridview. When I edit the column, I don't want let the user to type manually the date instead First, I want a calender popup or a button to select date from calendar. Second, for the time field, is there any template or gui that we can choose time as we select date from calendar??

for the first part of question ie not allowing user to type ,just use a javascipt function and call that function on onkeypress and onkeyup events of the text box.

option 1:

<script type="text/javascript">
function typingNotAllowed(CtrlID)
    {
    document.getElementById(CtrlID).value="";
    }
</script>

<form id="form1" runat="server">
    <div>
    <input type="text" id="someid"  onkeyup="typingNotAllowed(this.id)"   />
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="typingNotAllowed(this.id)"></asp:TextBox>
    </div>
</form>

option 2:

just add TextBox1.Attributes.Add("ReadOnly", "true"); in the code behind at load event

option 3: use jquery datetime picker in conjunction with any one of the above option (this will work for both the requirements)

I like the AJAX Control Toolkit's Calendar control. If you've never used the AJAX Control Toolkit, it is really simple. Here is a link to the calendar control. http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx

Here is the toolkit link so that you can download it if you think this will work for you. http://ajaxcontroltoolkit.codeplex.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM