Solved

on key press in code behind

Posted on 2013-01-27
3
1,682 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
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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 …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

822 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