我有一个不会在页面加载时显示的网格视图。 gridview位于更新面板内的一些asp:Panel中。我逐步完成了代码,所以我知道gridview有数据行。如果我将gridview移动到面板之外并更新面板,那么它将显示数据。有人知道为什么它不起作用,因为它位于面板和更新面板内部?
<%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation="false" MasterPageFile="~/CTPublic.master" CodeFile="Tank.aspx.vb" Inherits="CargoTank_Internal_Tank" %>
<div style="padding-top:9px; width:100%; min-width:800px; " >
<asp:UpdatePanel ID="udpTank" runat="server" >
<ContentTemplate>
<ajaxToolkit:RoundedCornersExtender runat="server" BorderColor="#3260a0" Corners="All" Radius="5" Color="#98B9C9" TargetControlID="pnlTank" ID="ajRCEpnlTank" ></ajaxToolkit:RoundedCornersExtender>
<asp:Panel runat="server" BackColor="#ecece7" Width="95%" ID="pnlTank" >
<div >
<div style="float:left; width:70%; background-color:#98B9C9; height:19px;">Tanks</div>
<div style="float:right; width:30%; height:19px;background-color:#98B9C9; text-align:right">
<asp:Button ID="btnAddNewTank" style="background:transparent; border:0px;" runat="server" Font-Underline="true" size="1" Font-Bold=true text="Add New" />
</div>
<div style="padding-top:19px;"></div>
</div>
<div style="width:100%;">
<table width="100%">
<tr>
<td colspan="6" class="tdheaderbar">Search Tanks
</td>
</tr>
<tr>
<td>CT #</td>
<td><asp:TextBox runat="server" ID="txtCTNumber" ></asp:TextBox></td>
<td>Serial #</td>
<td><asp:TextBox runat="server" ID="txtSerialNumber" MaxLength="17"></asp:TextBox></td>
<td>City</td>
<td><asp:TextBox runat="server" ID="txtCity"></asp:TextBox></td>
</tr>
<tr>
<td>Capacity</td>
<td><asp:TextBox runat="server" ID="txtCapacity"></asp:TextBox></td>
<td>Unit #</td>
<td><asp:TextBox runat="server" ID="txtUnitNumber"></asp:TextBox></td>
<td>License State</td>
<td><asp:DropDownList EnableViewState="true" runat="server" ID="ddlState" DataSourceID="linqStates"
Width="156px" DataTextField="StateText" DataValueField="StateID"></asp:DropDownList>
<asp:LinqDataSource ID="linqStates" runat="server"
ContextTypeName="DataClassesDataContext" TableName="States">
</asp:LinqDataSource>
</td>
</tr>
<tr>
<td>Tank Type</td>
<td>
<asp:DropDownList runat="server" ID="ddlTankType" Width="156px"
></asp:DropDownList>
</td>
<td>Compartment</td>
<td><asp:TextBox runat="server" ID="txtCompartment"></asp:TextBox></td>
<td>License #</td>
<td><asp:TextBox runat="server" ID="txtLicenseNumber"></asp:TextBox></td>
</tr>
<tr>
<td>Manufacturer</td>
<td colspan="2">
<asp:DropDownList runat="server" ID="ddlManufacturer"
></asp:DropDownList>
</td>
<td><asp:CheckBox runat="server" ID="chkNoLogIn" Text="No Log In Associated" /></td>
<td></td> <td></td>
</tr>
<tr><td>Company</td>
<td colspan="5"> <asp:DropDownList runat="server" ID="ddlCompany" ></asp:DropDownList></td>
</tr>
<tr>
<td colspan="3">
</td>
<td><asp:Button runat="server" ID="btnSearch" Text="Search" /></td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<br />
<div style="padding-top:9px; width:100%; " id="divTankDetail" runat="server">
<asp:UpdatePanel ID="updTankDetail" runat="server" >
<ContentTemplate>
<ajaxToolkit:DropShadowExtender runat="server" ID="dsetank" TargetControlID="pnlTankDetail" TrackPosition="true" BehaviorID="pnlTankDetailHeader"></ajaxToolkit:DropShadowExtender>
<ajaxToolkit:DragPanelExtender runat="server" ID="dpeTankDetail" TargetControlID="pnlTankDetail" DragHandleID="pnlTankDetailHeader"></ajaxToolkit:DragPanelExtender>
<asp:Panel CssClass="TankpopupPosition" BackColor="LightBlue" Visible="false" runat="server" BorderColor="#3260a0" BorderWidth="2px" Width="801px" ID="pnlTankDetail" >
<asp:Panel runat="server" BorderColor="#3260a0" BorderWidth="1px" Width="800px" ID="pnlTankDetailHeader">
<div >
<div style="float:left; width:90%; background-color:#98B9C9; height:19px;">Tank Detail</div>
<div style="float:right; width:10%; border-right-width:2px; border-width:1px; border-color:#3260a0; height:19px;background-color:#98B9C9; text-align:right">
<asp:Button ID="btnClose" style="background:transparent; border:0px;" runat="server" size="1" Font-Bold=true text="X" />
</div>
<div style="padding-top:19px;"></div>
</div>
</asp:Panel>
<asp:Panel runat="server" Width="800px" ID="pnlTankDetailBody">
<div id="divTankDetailbody" runat="server" style="width:100%" >
<br />
<table width="100%">
<tr>
<td>CT #</td>
<td><asp:TextBox TabIndex="10" runat="server" BorderStyle="Inset" BorderColor="White" BorderWidth="2px" BackColor="Transparent" ID="txtCTNum" ReadOnly="true" ></asp:TextBox>
<asp:Label ID="lblCTNumber" runat="server" Text="*"></asp:Label> </td>
<td>Serial #</td>
<td><asp:TextBox TabIndex="14" runat="server" BorderStyle="Inset" BorderColor="White" BorderWidth="2px" ID="txtSeriaNum" MaxLength="17"></asp:TextBox>
<asp:Label ID="lblSerialNumber" runat="server" Text="*"></asp:Label> </td>
<td>City</td>
<td><asp:TextBox runat="server" TabIndex="18" BorderStyle="Inset" BorderColor="White" BorderWidth="2px" ID="txtOrignatedCity"></asp:TextBox></td>
</tr>
<tr>
<td>Capacity</td>
<td><asp:TextBox TabIndex="11" runat="server" BorderStyle="Inset" BorderColor="White" BorderWidth="2px" ID="txtTanktCapacity"></asp:TextBox>
<asp:Label ID="lblCapacity" runat="server" Text="*"></asp:Label> </td>
<td>Compartment</td>
<td><asp:TextBox runat="server" TabIndex="15" ID="txtCompartment2" BorderStyle="Inset" BorderColor="White" BorderWidth="2px"></asp:TextBox>
<asp:Label ID="lblCompartment" runat="server" Text="*"></asp:Label> </td>
<td>License #</td>
<td><asp:TextBox runat="server" BorderStyle="Inset" TabIndex="19" BorderColor="White" BorderWidth="2px" ID="txtLicenseNum"></asp:TextBox></td>
</tr>
<tr>
<td>Tank Type</td>
<td>
<asp:DropDownList runat="server" TabIndex="12" ID="ddlTankType2" Width="156px"
DataTextField="TankTypeName"
DataValueField="TankTypeName"></asp:DropDownList><asp:Label ID="lblTankType" runat="server" Text="*"></asp:Label> 
</td>
<td>Unit #</td>
<td><asp:TextBox runat="server" TabIndex="16" BorderStyle="Inset" BorderColor="White" BorderWidth="2px" ID="txtUnitNum"></asp:TextBox></td>
<td>License State</td>
<td>
<asp:DropDownList EnableViewState="true" Width="156px" TabIndex="20" runat="server" ID="ddlLicenseState" DataSourceID="linqStates"
DataTextField="StateText" DataValueField="StateID"></asp:DropDownList>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" TableName="States">
</asp:LinqDataSource>
</td>
</tr>
<tr>
<td>Manufacturer</td>
<td colspan="1">
<asp:DropDownList runat="server" TabIndex="13" ID="ddlManufacturer2"
>
</asp:DropDownList><asp:Label ID="lblManufacturer" runat="server" Text="*"></asp:Label> 
</td>
<td>Company</td>
<td colspan="3"> <asp:DropDownList runat="server" TabIndex="17" ID="ddlCompany2" ></asp:DropDownList><asp:Label ID="lblCompany2" runat="server" Text="*"></asp:Label></td>
</tr>
<tr>
<td colspan="6" align="center"><br />
<asp:Label ID="lblChangeOwnership" Font-Size="Medium" runat="server"></asp:Label>
<br />
<asp:CheckBox ID="chkChangeOwnership" runat="server" Text="Changing ownership" ForeColor="Red" Font-Bold="true" />
</td>
</tr>
<tr>
<td colspan="6" align="center">
<br />
<asp:Button runat="server" ID="btnAdd" TabIndex="21" Text="Add" Width="60px" />
<asp:Button runat="server" ID="btnUpdate" TabIndex="22" Text="Update" Width="60px" />
<asp:Button runat="server" ID="btnChangeOnwership" TabIndex="23" Text="Change" Width="60px" />
<asp:Button runat="server" ID="btnCancel" TabIndex="24" Text="Cancel" Width="60px" />
<br /><br />
<asp:GridView ID="grdTanks" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="Transparent" GridLines="None"
PagerSettings-Mode="NumericFirstLast" PageSize="10"
RowStyle-HorizontalAlign="left" Width="100%">
<AlternatingRowStyle CssClass="alternateItemStyle" />
<HeaderStyle CssClass="headerStyle" />
<PagerSettings Mode="NumericFirstLast" />
<RowStyle CssClass="itemStyle" />
<Columns>
<asp:BoundField DataField="CargoTankID" HeaderText="CT #" InsertVisible="False"
ReadOnly="True" SortExpression="CargoTankID" />
<asp:BoundField DataField="CompanyID" HeaderText="CompanyID"
SortExpression="CompanyID" Visible="false" />
<asp:BoundField DataField="OriginatedCity" HeaderText="OriginatedCity"
SortExpression="OriginatedCity" Visible="false" />
<asp:BoundField DataField="LicenseNumber" HeaderText="LicenseNumber"
SortExpression="LicenseNumber" Visible="false" />
<asp:BoundField DataField="LicenseState" HeaderText="LicenseState"
SortExpression="LicenseState" Visible="false" />
<asp:BoundField DataField="UnitNumber" HeaderText="Unit Number"
SortExpression="UnitNumber" Visible="false" />
<asp:TemplateField HeaderText="Company">
<ItemTemplate>
<%#DisplayCompanyName(Eval("CompanyID"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SerialNumber" HeaderText="Serial Number"
SortExpression="SerialNumber" />
<asp:BoundField DataField="Capacity" HeaderText="Capacity"
SortExpression="Capacity" />
<asp:TemplateField HeaderText="Manufacturer">
<ItemTemplate>
<%#DisplayManufacturer(Eval("ManufacturerID"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TankType" HeaderText="Tank Type"
SortExpression="TankType" Visible="false" />
<asp:BoundField DataField="Compartment" HeaderText="Compartment"
SortExpression="Compartment" Visible="false" />
<asp:BoundField DataField="DecalID" HeaderText="DecalID"
SortExpression="DecalID" Visible="false" />
<asp:TemplateField HeaderText="Decal Status">
<ItemTemplate>
<%#DisplayTestLink(Eval("CargoTankID"))%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
这是我背后的代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If (Me.Page.User.Identity.IsAuthenticated) Then
Dim db As DataClassesDataContext = New DataClassesDataContext()
Dim tanks = From t In db.CT_Tanks _
Select t
Me.grdTanks.DataSource = tanks
Me.grdTanks.DataBind()
Dim tanktype = (From t In db.CT_TankTypes _
Select t).ToList
ddlTankType.DataSource = tanktype
ddlTankType.DataTextField = "TankTypeName"
ddlTankType.DataValueField = "TankTypeName"
ddlTankType.DataBind()
ddlTankType.Items.Insert(0, "-- Select a Type --")
ddlTankType2.DataSource = tanktype
ddlTankType2.DataTextField = "TankTypeName"
ddlTankType2.DataValueField = "TankTypeName"
ddlTankType2.DataBind()
ddlTankType2.Items.Insert(0, "-- Select a Type --")
Dim manufacturer = (From m In db.CT_Manufacturers _
Select m).ToList
ddlManufacturer.DataSource = manufacturer
ddlManufacturer.DataTextField = "ManufacturerName"
ddlManufacturer.DataValueField = "ManufacturerID"
ddlManufacturer.DataBind()
ddlManufacturer.Items.Insert(0, "-- Select a Manufacturer --")
ddlManufacturer2.DataSource = manufacturer
ddlManufacturer2.DataTextField = "ManufacturerName"
ddlManufacturer2.DataValueField = "ManufacturerID"
ddlManufacturer2.DataBind()
ddlManufacturer2.Items.Insert(0, "-- Select a Manufacturer --")
Dim companies = (From c In db.CT_Companies _
Where c.IsOwner = True _
Select c Order By c.CompanyName Ascending).ToList
ddlCompany.DataSource = companies
ddlCompany.DataTextField = "CompanyName"
ddlCompany.DataValueField = "CompanyID"
ddlCompany.DataBind()
ddlCompany.Items.Insert(0, "-- Select a Company --")
ddlCompany2.DataSource = companies
ddlCompany2.DataTextField = "CompanyName"
ddlCompany2.DataValueField = "CompanyID"
ddlCompany2.DataBind()
ddlCompany2.Items.Insert(0, "-- Select a Company --")
End If
End If
End Sub
答案 0 :(得分:0)
不确定但添加此内容可能会帮助您
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
答案 1 :(得分:0)
在您对gridview进行数据绑定后,似乎没有触发您的更新面板
尝试:
<asp:UpdatePanel ID="updTankDetail" runat="server" UpdateMode="Conditional">
然后在你的代码后面放
updTankDetail.Update()
答案 2 :(得分:0)
我试过这个地方我的gridview里面的面板下的更新面板及其工作..
<asp:Panel ID="pnContainer" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvempgrade" runat="server" AutoGenerateColumns="False" GridLines="None"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onrowcancelingedit="gvempgrade_RowCancelingEdit"
onrowediting="gvempgrade_RowEditing"
onrowupdating="gvempgrade_RowUpdating" ShowFooter="True"
onrowcommand="gvempgrade_RowCommand"
onrowdeleting="gvempgrade_RowDeleting">
<FooterStyle BackColor="#A86E07" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#603813" />
<Columns>
<asp:TemplateField HeaderText="<%$ Resources:Resources, SrNo %>" ItemStyle-CssClass="srcenteralg" ItemStyle-Width="30" HeaderStyle-Width="55" >
<ItemTemplate >
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text='<%# Bind("id_grd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Resources, Grade %>" >
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblgrade" runat="server" Text='<%# Bind("grade_grd") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtempgrade" Width="55" CssClass="alphabetsOnlynospace" runat="server" Text='<%# Bind("grade_grd") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate >
<asp:TextBox ID="txtfempgrade" CssClass="alphabetsOnlynospace" runat="server" Width="55"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Resources, Description %>" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lbldiscription" runat="server" Text='<%# Bind("description_grd") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtempdescription" CssClass="alphabetsOnly" runat="server" Text='<%# Bind("description_grd") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfempdescription" CssClass="alphabetsOnly" runat="server"></asp:TextBox>
</FooterTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Resources, Maxctc %>" HeaderStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblmaxctc" runat="server" Text='<%# Bind("max_ctc_grd") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtmaxctc" CssClass="numbersOnly" MaxLength="10" Width="100" runat="server" Text='<%# Bind("max_ctc_grd") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfmaxctc" CssClass="numbersOnly" MaxLength="10" Width="100" runat="server"></asp:TextBox>
</FooterTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="<%$ Resources:Resources, Minctc %>" HeaderStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblminctc" runat="server" Text='<%# Bind("min_ctc_grd") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtminctc" MaxLength="10" CssClass="numbersOnly" Width="100" runat="server" Text='<%# Bind("min_ctc_grd") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfminctc" MaxLength="10" CssClass="numbersOnly" Width="100" runat="server"></asp:TextBox>
</FooterTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" ItemStyle-Width="190px" FooterStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" >
<ItemTemplate>
<asp:Button ID="btnedit" runat="server" CausesValidation="True" CssClass="btngradiant"
CommandName="Edit" Text="<%$ Resources:Resources, Edit %>"></asp:Button >
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnupdate" runat="server" CausesValidation="True" CssClass="btngradiant"
CommandName="Update" Text="Update" OnClientClick="return updatevalidation();" ></asp:Button >
<asp:Button ID="btncancel" runat="server" CausesValidation="False" CssClass="btngradiant"
CommandName="Cancel" Text="Cancel"></asp:Button >
</EditItemTemplate>
<FooterTemplate >
<asp:Button ID="btninsert" runat="server" Text="<%$ Resources:Resources, Add %>" CommandName="Add" CssClass="btngradiant" OnClientClick="return validation();" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="LinkButton2" runat="server" CausesValidation="False" CssClass="btngradiant" OnClientClick='return confirm("Are you sure you want to delete this entry?");'
CommandName="Delete" Text="<%$ Resources:Resources, Delete %>"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#A86E07" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#A86E07" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#d9d9d9" />
<AlternatingRowStyle BackColor="White" ForeColor="#A86E07" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
代码背后:
On pageLoad()
if (!Page.IsPostBack)
{
DataTable dtfetch = emp.Fetchreord();
gvempgrade.DataSource = dtfetch;
gvempgrade.DataBind();
}
注意:当您收到与extendercontrolbase.cs
相关的错误,意味着dll丢失时,请尝试评论所有Extender控件,看看它是否有效
答案 3 :(得分:0)
标题:页面加载时无法看到asp.net gridview
我在代码中看到您使用的面板为id="ID="pnlTankDetail""
,面板ID="pnlTankDetail"
的属性为Visible =&#34; False&#34; so the gridview
grdTanks can't show in page load. You should change to
可见=&#34 ; true to see gridview. And
i think the
div tag not have property
runnat =&#34; server&#34;`。希望得到这个帮助。