Dynamically control the status and input value of textbox in the DataGrid !!

Source: Internet
Author: User
The functions to be implemented are:
1. textbox "quantity used" is dynamically generated.
2. dynamically control the "available quantity" status in the background.
3. The input quantity for controlling "available quantity" cannot be greater than "available quantity ".
If the "available quantity" is greater than "available quantity", you cannot enter it !!!
Direct script implementation saves the trouble of submitting, checking, returning, and pop-up dialog boxes.

:

Front-end: < ASP: DataGrid ID = "Dgximu" Runat = "Server" Datakeyfield = "TID" Onupdatecommand = "Update" Oncancelcommand = "Cancel"
Oneditcommand = "Edit" Autogeneratecolumns = "False" Bordercolor = "# Cccccc" Borderstyle = "NONE" Borderwidth = "1px" Backcolor = "White" Cellpadding = "3"
Width = "100%" Allowpaging = "True" >
< Selecteditemstyle Font-bold = "True" Forecolor = "# F7f7f7" Backcolor = "# 738a9c" > </ Selecteditemstyle >
< Alternatingitemstyle Backcolor = "White" > </ Alternatingitemstyle >
< Itemstyle Forecolor = "Black" Backcolor = "White" > </ Itemstyle >
< Headerstyle Font-bold = "True" Forecolor = "#336699" Backcolor = "# E6eef7" > </ Headerstyle >
< Footerstyle Forecolor = "#336699" Backcolor = "# E6eef7" > </ Footerstyle >
< Columns >
< ASP: boundcolumn Datafield = "Whinno" Readonly = "True" Headertext = "Warehouse receiving Ticket No" >
< Headerstyle Width = "25%" > </ Headerstyle >
</ ASP: boundcolumn >
< ASP: boundcolumn Datafield = "Whindate" Readonly = "True" Headertext = "Warehouse receiving time" >
< Headerstyle Width = "25%" > </ Headerstyle >
</ ASP: boundcolumn >
< ASP: boundcolumn Datafield = "Warename" Headertext = "Database" >
< Headerstyle Width = "10%" > </ Headerstyle >
</ ASP: boundcolumn >
< ASP: boundcolumn Datafield = "Qtyky" Headertext = "Available quantity" >
< Headerstyle Width = "15%" > </ Headerstyle >
</ ASP: boundcolumn >
< ASP: boundcolumn Headertext = "Available quantity" >
< Headerstyle Width = "10%" > </ Headerstyle >
</ ASP: boundcolumn >
</ Columns >
</ ASP: DataGrid >

Add a piece of javascript: < Script Language = " Javascript " >
Function Isint (OBJ, strqtyky)
{
If (Event. keycode < 48   | Event. keycode > 57 )
{
Event. keycode = 0 ;
}
Else
{
// Original collection quantity
VaR Qtylyold
If (Obj. Value = "" )
Qtylyold =   0 ;
Else
Qtylyold = OBJ. value;

// Number of presses
VaR Qtylynew
Qtylynew = Parseint (event. keycode) - 48 ;

If (Qtylyold + Qtylynew) > Parseint (strqtyky ))
{
Event. keycode = 0 ;
}
}
}
</ Script >

Background: Private   Void Dgximu_itemdatabound ( Object Sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
Try
{
Oasys. Public. Public objpub = New Oasys. Public. Public ();
For ( Int I = 0 ; I < Dgximu. Items. Count; I ++ )
{
// Primary Key Column
String Strtid = Dgximu. datakeys [I]. tostring ();

//Available quantity Column
Tablecell cellqtyky=Dgximu. items [I]. cells [4];
StringStrqtyky=Cellqtyky. text;

// Number of used Columns
Tablecell cellqtyly = Dgximu. items [I]. cells [ 5 ];
Cellqtyly. Controls. Clear ();

// Number of used columns-control readonly
Textbox TB =   New Textbox ();
TB. cssclass =   " Input_text " ;
TB. Width =   80 ;
TB. maxlength =   10 ;
TB. enableviewstate =   True ;
TB. Attributes. Add ( " Onkeypress " , @" Isint (this, " + Strqtyky + " ) " );
Cellqtyly. Controls. Add (TB );
}
Objpub. Close ();
}
Catch (Exception ex)
{
Throw Ex;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.