none
Gridview Label.text Javascript RRS feed

Yanıtlar

  • <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
          runat="server" AutoGenerateColumns="false">
          <Columns>
              <asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
              <asp:TemplateField>
                  <ItemTemplate>
                      <asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText = "Name">
                  <ItemTemplate>
                      <asp:Button Text="Fetch" runat="server" OnClientClick="return FetchLabel(this)" />
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
      </asp:GridView>
      <br />
      <asp:Button Text="Fetch All Labels" runat="server" OnClientClick="return FetchAllLabels()" />
      <script type="text/javascript">
          function FetchLabel(button) {
              var row = button.parentNode.parentNode;
              var label = GetChildControl(row, "lblName");
              alert(label.innerHTML);
              return false;
          };
          function FetchAllLabels() {
              var rows = document.getElementById("<%=GridView1.ClientID %>").getElementsByTagName("tr");
              var message = "";
              for (var i = 1; i < rows.length; i++) {
                  var label = GetChildControl(rows[i], "lblName");
                  message += "Row: " + i + ": " + label.innerHTML + "\r\n";
              }
              alert(message);
              return false;
          };
          function GetChildControl(element, id) {
              var child_elements = element.getElementsByTagName("*");
              for (var i = 0; i < child_elements.length; i++) {
                  if (child_elements[i].id.indexOf(id) != -1) {
                      return child_elements[i];
                  }
              }
          };
      </script>
    BU İŞİNE YARAR KENDİNCE DÜZENLEME YAP BAKALIM


    19 Ağustos 2015 Çarşamba 08:41

Tüm Yanıtlar

  • gridview içerisindeki her labela bir id verip buna göre getelementbyid ile alabilirsiniz. Biraz daha açabilirseniz daha net cevap alabilirsiniz. Örnek kod falan gösterebilirseniz daha iyi olur.

    oguzkurtcuoglu.com


    18 Ağustos 2015 Salı 11:21
  • a tagına direk Eval ile sunucudan gelen alanı yazdım, yakaladım
    19 Ağustos 2015 Çarşamba 08:01
  • <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
          runat="server" AutoGenerateColumns="false">
          <Columns>
              <asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
              <asp:TemplateField>
                  <ItemTemplate>
                      <asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText = "Name">
                  <ItemTemplate>
                      <asp:Button Text="Fetch" runat="server" OnClientClick="return FetchLabel(this)" />
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
      </asp:GridView>
      <br />
      <asp:Button Text="Fetch All Labels" runat="server" OnClientClick="return FetchAllLabels()" />
      <script type="text/javascript">
          function FetchLabel(button) {
              var row = button.parentNode.parentNode;
              var label = GetChildControl(row, "lblName");
              alert(label.innerHTML);
              return false;
          };
          function FetchAllLabels() {
              var rows = document.getElementById("<%=GridView1.ClientID %>").getElementsByTagName("tr");
              var message = "";
              for (var i = 1; i < rows.length; i++) {
                  var label = GetChildControl(rows[i], "lblName");
                  message += "Row: " + i + ": " + label.innerHTML + "\r\n";
              }
              alert(message);
              return false;
          };
          function GetChildControl(element, id) {
              var child_elements = element.getElementsByTagName("*");
              for (var i = 0; i < child_elements.length; i++) {
                  if (child_elements[i].id.indexOf(id) != -1) {
                      return child_elements[i];
                  }
              }
          };
      </script>
    BU İŞİNE YARAR KENDİNCE DÜZENLEME YAP BAKALIM


    19 Ağustos 2015 Çarşamba 08:41
  • <asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
          runat="server" AutoGenerateColumns="false">
          <Columns>
              <asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
              <asp:TemplateField>
                  <ItemTemplate>
                      <asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText = "Name">
                  <ItemTemplate>
                      <asp:Button Text="Fetch" runat="server" OnClientClick="return FetchLabel(this)" />
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
      </asp:GridView>
      <br />
      <asp:Button Text="Fetch All Labels" runat="server" OnClientClick="return FetchAllLabels()" />
      <script type="text/javascript">
          function FetchLabel(button) {
              var row = button.parentNode.parentNode;
              var label = GetChildControl(row, "lblName");
              alert(label.innerHTML);
              return false;
          };
          function FetchAllLabels() {
              var rows = document.getElementById("<%=GridView1.ClientID %>").getElementsByTagName("tr");
              var message = "";
              for (var i = 1; i < rows.length; i++) {
                  var label = GetChildControl(rows[i], "lblName");
                  message += "Row: " + i + ": " + label.innerHTML + "\r\n";
              }
              alert(message);
              return false;
          };
          function GetChildControl(element, id) {
              var child_elements = element.getElementsByTagName("*");
              for (var i = 0; i < child_elements.length; i++) {
                  if (child_elements[i].id.indexOf(id) != -1) {
                      return child_elements[i];
                  }
              }
          };
      </script>
    BU İŞİNE YARAR KENDİNCE DÜZENLEME YAP BAKALIM


    teşekkürler...
    19 Ağustos 2015 Çarşamba 08:49