Solved

on key press in code behind

Posted on 2013-01-27
3
1,797 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38823696
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
ID: 38824803
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
ID: 38825681
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 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