0

How to textbox values from gridview on click of a linkbutton using jquery here is my gridview

  <asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="false" GridLines="Both">
            <Columns>
                <asp:TemplateField HeaderText="Email">
                    <ItemTemplate>
                        <asp:TextBox ID="txtEmail" runat="server" Text='<%#Eval("Emailid") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:TextBox ID="txtName" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkgettext" runat="server" Text="Gettextboxvalue"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

I tried something like

  alert($(this).parent("td").parent("tr").find("input:text").val());

I Can able to find first value of a textbox but facing a problem to get next textbox value i.e txtName from second td Please suggest Also suggest if you have any solution with javascript

4 Answers 4

1

May this will help you...

    function GVtxtAmount() {
    var GVMaintainReceiptMaster = document.getElementById('<%= GVMaintainReceiptMaster.ClientID %>');

    for (var rowId = 1; rowId < GVMaintainReceiptMaster.rows.length; rowId++) {
        var txtbx = GVMaintainReceiptMaster.rows[rowId].cells[0].children[0];
        alert(txtbx.value);
    }
    return false;
}
Sign up to request clarification or add additional context in comments.

Comments

0

you can use end selector as follows

 $( "[ @id *= 'txtEmail']" ).text();

Here is a good link about how to find the element like selection

[http://www.bennadel.com/blog/1003-Cool-jQuery-Predicate-Selectors.htm][1]

You will find like this

 //first find the tr 
 var tr= $(this).parent("td").parent("tr");
 and then use like selector with.

 var Email=$(this).parent("td").parent("tr").find($( "[ @id *= 'txtEmail']" )).val();
 var Name= $(this).parent("td").parent("tr").find($( "[ @id *= 'txtName']" )).val();

2 Comments

got solution alert($(a).parent("td").parent("tr").find(".txtclass1").val());
do you know what are using. You are using a class selector. So if you have put css-classes then it is ok.
0
$('#<%=lnkgettext.ClientID %>').click(function(){
    var email=$(this).parent('td').parent('tr').find('#<%=txtEmail.ClientID%>').val();        
    var name=$(this).parent('td').parent('tr').find('#<%=txtName.ClientID%>').val();
}

or

$(this).parent("td").parent("tr").each(function(){
    $(this).find('td').each(function(){
        //Do whatever you want, you can use $(this) to get value of current cell
    })
})

10 Comments

it's a gridview so the it will change at the right time. there will be unique id's for every column.
What exactly do you want to say? Are you saying that the texbox controls will change their ID?
yes since it is a gridview and it will have many rows at runtime. With different id's like txtEmail_0 and txtEmail_1 etc and if the page is inherited by master page then it will be like ct0_txtEmail_0 etc
Yes, It will have many rows .. But the control names never change.. Have you tried my code?
can there be two control of same ie in asp.net ??
|
0

try this, it should work perfectly

$('a[id$=lnkgettext]').click(function(){
    var email=$(this).parent('tr').find('input[id=txtEmail]').val();        
    var name=$(this).parent('tr').find('input[id=txtName]').val();
    alert(email+" "+name);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.