DynamicPopulateExtender

mercoledì 28 agosto 2013 - 13.02

jjchuck Profilo | Senior Member

ciao a tutti
studiando il controllo nel testo Wrox Professional.ASP.NET.4.in.CSharp and VB 2010
cè una demo ottima per chi lavora con i gridview e deve visualizzare nello stesso diverse viste con un semplice click ...

ho inserito la demo pari pari nel mio sito con l'unica differenza che cè una master page ...
risultato non mi restituisce nulla...
se tolgo la master page ottengo 'Web Service call failed: 500'

posto il codice

Imports System.Data.SqlClient Imports System.Data Imports System.IO Partial Class _Commerciale_Inevaso Inherits System.Web.UI.Page <System.Web.Services.WebMethodAttribute()> <System.Web.Script.Services.ScriptMethodAttribute()> Public Shared Function GetDynamicContent(ByVal contextKey As System.String) As System.String Dim conn As SqlConnection Dim cmd As SqlCommand Dim cmdString As String = "SELECT ..." Select Case contextKey Case "1" cmdString = "Select ..." Case "2" cmdString = "Select ..." End Select conn = New SqlConnection("xxx") cmd = New SqlCommand(cmdString, conn) conn.Open() Dim myReader As SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) Dim dt As New DataTable dt.Load(myReader) myReader.Close() Dim myGrid As New GridView myGrid.ID = "GridView1" myGrid.DataSource = dt myGrid.DataBind() Dim sw As New StringWriter Dim htw As HtmlTextWriter = New HtmlTextWriter(sw) myGrid.RenderControl(htw) htw.Close() Return sw.ToString() End Function End Class

markup

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Inevaso.aspx.vb" Inherits="_Commerciale_Inevaso" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<script type="text/javascript" language="javascript">
function updateGrid(value) {
var behavior = $find('DynamicPopulateExtender1');
if (behavior) {
behavior.populate(value);
}
}

</script>
<div>

<asp:DynamicPopulateExtender ID="DynamicPopulateExtender1" runat="server"
TargetControlID="Panel1" ServiceMethod="GetDynamicContent">
</asp:DynamicPopulateExtender>
<div onclick="updateGrid(this.value);" value='0'>
<asp:LinkButton ID="LinkButton1" runat="server"
OnClientClick="return false;" >Customers</asp:LinkButton></div>
<div onclick="updateGrid(this.value);" value='1'>
<asp:LinkButton ID="LinkButton2" runat="server"
OnClientClick="return false;">Employees</asp:LinkButton></div>
<div onclick="updateGrid(this.value);" value='2'>
<asp:LinkButton ID="LinkButton3" runat="server"
OnClientClick="return false;">Products</asp:LinkButton></div>

<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</asp:Content>
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5