Friday 18 July 2014

Set and get textboxs and labels values inside gridview using jquery


Select all labels with id= "lblID" inside gridview

$('#<%=gdRows.ClientID %>').find('span[id$="lblID"]').text('Your text.');

Select particular label control out of all the labels with id= "lblID" inside gridview

var $arrL = $('#<%=gdRows.ClientID %>').find('span[id$="lblID"]');
var $lbl = $arrL[0];
$($lbl).text('Your text...');

Similarly, you can also find textbox. Select all textbox with id= "txtID" inside gridview

$('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]').val('Your value.');

Select particular textbox control out of all the textboxes with id="txtID" inside gridview

var $arrT = $('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]');
var $txt = $arrT[0];
$($txt).val('text...');

//HTML
<asp:GridView runat="server" ID="dgv" AutoGenerateColumns="False" ShowFooter="true">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="id" />
        <asp:TemplateField HeaderText="from">

            <ItemTemplate>
               <asp:TextBox ID="txtfromff" runat="server"></asp:TextBox>
            </ItemTemplate>
            <FooterTemplate>
            <asp:TextBox ID="txt_from" class="d_from" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="to"> 
            <ItemTemplate>
            <asp:TextBox ID="txttott"  runat="server"></asp:TextBox>
              
            </ItemTemplate>
            <FooterTemplate>            
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>

</asp:GridView>


//Script
<script type="text/javascript">

function SetDissVenderValue() {
                    var ddlvalue = $('#<%=ddl_venderDiss.ClientID%> option:selected').text();
                    var $arrT = $('#<%=DGV_Dissimination.ClientID %>').find('input:text[id$="txt_vender"]');
                    var $txt = $arrT[0];
                    $($txt).val(ddlvalue);
                    $find('showselecven').hide();
                    return false;
                }
 </script>


No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...