aspx部分代码:
<asp:Panel ID="Panel2" runat="server" Height="100%" Width="100%">
<div id="div4">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Height="50px" Width="220px" AutoGenerateEditButton="True" OnModeChanging="DetailsView1_ModeChanging" OnModeChanged="DetailsView1_ModeChanged">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<Fields>
<asp:TemplateField HeaderText="所属ID" SortExpression="bbc_0">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("bbc_0") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="版面名称" SortExpression="bbc_1">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("bbc_1") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("bbc_1") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("bbc_1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="分类">
<EditItemTemplate><asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="版面说明" SortExpression="bbc_4">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("bbc_4") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("bbc_4") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("bbc_4") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="版面版主" SortExpression="bbc_3">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("bbc_3") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("bbc_3") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("bbc_3") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="访问级别">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>
</div>
</asp:Panel>
cs部分代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Panel1.Visible = true;
Panel2.Visible = false;
}
}
点击了某个按钮后
{
Panel1.Visible = false;
Panel2.Visible = true;
DataTable dt = pwebdata.retable("select * ,bst_4.puk_1 as bbc_111 from bst_1 inner join bst_4 on bst_4.puk_0=bst_1.bbc_5 where bbc_0=1");
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}
现在的问题是 DetailsView1的模式不知道怎样才能转换。。。
代码如下
protected void DetailsView1_ModeChanged(object sender, EventArgs e)
{
Response.Write(DetailsView1.CurrentMode.ToString());
switch (DetailsView1.CurrentMode)
{
case DetailsViewMode.Edit:
Response.Write("edit");
break;
case DetailsViewMode.Insert:
Response.Write("insert");
break;
case DetailsViewMode.ReadOnly:
Response.Write("ReadOnly");
break;
}
}
protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
switch (e.NewMode)
{
case DetailsViewMode.Edit:
break;
case DetailsViewMode.ReadOnly:
break;
}
}
页面没有变化,也就是说是ReadOnly模式,DetailsView1_ModeChanged没有触发.