其实很简单,就是 如何用一个按钮,在DetailsView控件的新增状态下,给其中的模板列的一个TextBox1赋值
比如我要新增一个客户的维护 信息,则按新增后,客户名称最好是设置为主网页传过来的参数(客户名称)。
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------下面是源代码:---------------------------------------------------------------------------------
---------------------------------------------------------------------------------<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)        '我想在此用一句代码,当DetailsView1为新增状态时,按此钮,客户名称列 赋值为 我想要的一个字符串值
       
    End Sub
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:TextBox ID="TextBox2" runat="server" Height="57px" TextMode="MultiLine" 
            Width="237px">在新增状态下,按一下按钮则DetailsView1中【客户名称】的值就等于此处的内容</asp:TextBox>
    
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="设置客户名称值" />
    
    </div>
    <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
        AutoGenerateRows="False" DataKeyNames="客户名称" DataSourceID="SqlDataSource1" 
        Height="50px" Width="377px" BackColor="#DEBA84" BorderColor="#DEBA84" 
        BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
        <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
        <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
        <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
        <Fields>
            <asp:TemplateField HeaderText="客户名称" SortExpression="客户名称">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("客户名称") %>'></asp:Label>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Height="19px" 
                        Text='<%# Bind("客户名称") %>' Width="191px"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("客户名称") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="软件安装人员" HeaderText="软件安装人员" 
                SortExpression="软件安装人员" />
            <asp:BoundField DataField="软件安装时间" HeaderText="软件安装时间" 
                SortExpression="软件安装时间" />
            <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
        <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:guestbookConnectionString %>" 
        DeleteCommand="DELETE FROM [软件安装表] WHERE [客户名称] = @客户名称" 
        InsertCommand="INSERT INTO [软件安装表] ([客户名称], [软件安装人员], [软件安装时间]) VALUES (@客户名称, @软件安装人员, @软件安装时间)" 
        SelectCommand="SELECT [客户名称], [软件安装人员], [软件安装时间] FROM [软件安装表]" 
        UpdateCommand="UPDATE [软件安装表] SET [软件安装人员] = @软件安装人员, [软件安装时间] = @软件安装时间 WHERE [客户名称] = @客户名称">
        <DeleteParameters>
            <asp:Parameter Name="客户名称" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="软件安装人员" Type="String" />
            <asp:Parameter Name="软件安装时间" Type="DateTime" />
            <asp:Parameter Name="客户名称" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="客户名称" Type="String" />
            <asp:Parameter Name="软件安装人员" Type="String" />
            <asp:Parameter Name="软件安装时间" Type="DateTime" />
        </InsertParameters>
    </asp:SqlDataSource>
    </form>
</body>
</html>

解决方案 »

  1.   

    其实很简单,就是 如何用一个按钮,在DetailsView控件的新增状态下,给其中的模板列的一个TextBox1赋值 
    比如我要新增一个客户的维护 信息,则按新增后,客户名称最好是设置为主网页传过来的参数(客户名称)。 
      

  2.   

    很少用那控件
    提供思路:detailview控件最终在客户端生成的是table 
    可以用js处理 找到table里的控件 然后赋值
      

  3.   

            Dim TextBox1_test As New DropDownList        TextBox1_test = DetailsView1.Rows(0).Cells(1).FindControl("DropDownList1")        TextBox1_test.SelectedValue = "学校"自己解决了。