Can't select grid item via jQuery

This is the next question for ASP.NET How to pass container value as javascript argument

Darin Dimitrov kindly provided his answer using jQuery , <br / "> But for some reason I was unable to select the grid row I wanted.

Here is the jQuery used for row selection.

$(function() {
    $('#_TrustGrid input[name^=trustDocIDTextBox]').each(function(index) {
        $(this).click(function() {
            alert('Hello world = ' + index);
            setGridInEditMode(index);
        });
    });
});

      

Here is the actual HTML markup.

<input 
    id="_TrustGrid_ctl16_ctl05_ctl00_trustDocIDTextBox" 
    type="text" value="198327493" 
    name="_TrustGrid$ctl16$ctl05$ctl00$trustDocIDTextBox"/>

      

I just started using jQuery tonight and am going through the official jQuery Selectors but with no success.




Did I miss something?

+1


source to share


3 answers


I don't know why choosing via #_TrustGrid

didn't work. I was able to work around the problem by specifying :input

as shown below.



    $(function() {
        //$('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
        $(':input[id$=trustDocIDTextBox]').each(function(index) {
            $(this).click(function() {
                alert('Hello world = ' + index);
                setGridInEditMode(index);
            });
        });
    });

      

0


source


What I did to keep the full ID of the control I was using in my .aspx page:

<input type="hidden" 
       id="SubcontractorDropDownID" 
       value="<%= SubcontractorDropDown.ClientID %>" />

      



Then you can just get the id value and then use it in your request to find out which string to use.

0


source


At first glance, I think you just want "$" instead of "^" and you should target the ID and not the NAME in your selector?

$(function() {
    $('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
        $(this).click(function() {
            alert('Hello world = ' + index);
            setGridInEditMode(index);
        });
    });
});

      

0


source







All Articles