none
DetailsView如何应用ajax RRS feed

  • 问题

  • <asp:TemplateField HeaderText="是否精品">
                                <EditItemTemplate>
                                   <asp:CheckBox ID="是否精品" AutoPostBack="true" runat="server" Checked='<%#Bind("是否精品")%>' OnCheckedChanged="是否精品_CheckedChanged" />
                                </EditItemTemplate>
                                <ItemTemplate>
                                  <asp:CheckBox ID="是否精品" Enabled="false" runat="server" Checked='<%#Bind("是否精品")%>' /> 
                                </ItemTemplate>
                                </asp:TemplateField>
                            <asp:TemplateField HeaderText="是否首页精品推荐">
                                <EditItemTemplate>
                                   <asp:CheckBox AutoPostBack="true" ID="是否首页精品推荐" runat="server" Checked='<%#Bind("是否首页精品推荐")%>' OnCheckedChanged="是否首页精品推荐_CheckedChanged" />
                                </EditItemTemplate>
                                <ItemTemplate>
                                  <asp:CheckBox ID="是否首页精品推荐" Enabled="false" runat="server" Checked='<%#Bind("是否首页精品推荐")%>' /> 
                                </ItemTemplate>
                            </asp:TemplateField>
    这段代码在DetailsView里,我的目的是达到“如果不是精品那么也不是首页精品推荐,是首页精品推荐那么肯定是精品”,目前这一目的已经达到,但是在点击CheckBox时会发生闪烁,如果加上<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> ,并且在DetailsView前后加上<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>,在点击编辑后,会出现“Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: 在服务器上处理请求时出现未知错误。服务器返回的状态码为: 404”;

    如何达到不刷新的效果?
    2010年2月26日 3:16

答案

  • 你好,

    参考下面的代码试试。
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">  
    
        protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
        {
            
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server">
        </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                DataKeyNames="Id" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
                <Fields>
                    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" 
                        ReadOnly="True" SortExpression="Id" />
                    <asp:BoundField DataField="ImageName" HeaderText="ImageName" 
                        SortExpression="ImageName" />
                    <asp:BoundField DataField="Des" HeaderText="Des" SortExpression="Des" />
                    <asp:BoundField DataField="Path" HeaderText="Path" SortExpression="Path" />
                    <asp:BoundField DataField="CategoryId" HeaderText="CategoryId" 
                        SortExpression="CategoryId" />
                        <asp:CheckBoxField HeaderText="CheckBox" Text="CheckBox"   ReadOnly="True" />
                        <asp:TemplateField>
                        <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1"  runat="server" 
                                Text="Checkbox" oncheckedchanged="CheckBox1_CheckedChanged1" AutoPostBack="true"/>
                        </ItemTemplate>
                        </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:test_EmployeeInfo_SKConnectionString2 %>" 
                SelectCommand="SELECT * FROM [Images]"></asp:SqlDataSource>       
            </ContentTemplate>
            <Triggers></Triggers>
            </asp:UpdatePanel>  
       
        </div>
        </form>
    </body>
    </html>
    

    Microsoft Online Community Support
    2010年3月1日 4:02