Solved

on key press in code behind

Posted on 2013-01-27
3
1,606 Views
Last Modified: 2013-03-25
Gridview edit I want to check and make sure a valid value is entered.


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           
           
            GridView gv = (GridView)sender;
            GridView1.Rows[e.NewEditIndex].Attributes.Add("onkeyup", "keyPress(this)");
                        gv.EditIndex = e.NewEditIndex;
            gv.DataBind();
        }
<script type="text/javascript">
    function keyPress(e)
    {


        alert('hi key pressed');

        


    }
</script>

Open in new window

0
Comment
Question by:mikensu12
3 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
Comment Utility
i think you should bind this event on row data bound instead of rowediting

example:
    Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

 Dim btnPreview As Button = e.Row.Cells(10).Controls(1)
'here we search for the control


            If Not btnPreview Is Nothing Then
                btnPreview.Attributes.Add("OnClick", "javascript:showlnk(" & btnPreview.CommandArgument & ");")
            

            End If



 End If
    End Sub




showlnk is a javascript function

Open in new window

0
 
LVL 20

Expert Comment

by:informaniac
Comment Utility
You want to check the value of a TextBox in the row?

protected void gvTextBox_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex == gvTextBox.EditIndex)
            {
                TextBox txt1 = e.Row.FindControl("txt1") as TextBox;
                 txt1.Attributes.Add("onkeyup", "keyPress(this)");
            }
        }

Open in new window

0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
Comment Utility
u make keypress event in edit mode of Gridview text box like this also

<EditItemTemplate>
                        <asp:TextBox ID="gvdtxtHR" onkeypress= "javascript:return KeyPress(event, this,3,2);" runat="server" Text='<%# Bind("hotel_rate") %>' Width="40px" ></asp:TextBox>                      
</EditItemTemplate>

Refer : http://forums.asp.net/t/1235027.aspx

Javascript function

function KeyPress(event, ctlName,explen,decLen)

    {
   
    var cntNbr=document.getElementById(ctlName.id).value;
      
    } 

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now