c# - DetailsView 插入的默认值

标签 c# asp.net data-binding asp.net-membership

当用户转到指定页面时,我将 DetailsView 附加到 SqlDataSource 并且已经设置为插入模式。我实际上是将它用作某些事件的注册页面。我不想让用户输入他们的“用户名”,而是希望该字段根据已经登录的用户自动填充。

对于如何让 User.Identity.Name 成为出现在 Page_load 上的默认值,或者如何编写覆盖 DetailsViewInsertEventArgs 的代码,有没有人有任何建议?当然,如果我完全偏离基地,那么其他建议会很棒。

我在后台使用 C# 代码。

谢谢, 迈克

最佳答案

你可以这样做:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DetailsView1.DefaultMode = DetailsViewMode.Insert;
            if (DetailsView1.FindControl("TextBox1") != null)
            {
                TextBox txt1 = (TextBox)DetailsView1.FindControl("TextBox1");
                txt1.Text = User.Identity.Name.ToString();
            }
        }
    }

关于c# - DetailsView 插入的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1501310/

相关文章:

c# - ASP.NET 中的自制 MessageBox.Show()

asp.net - ASP.NET 中 DataGrid 和 GridView 之间的区别?

c# - 适用于 iis6 和 iis7 的 Web 项目 MSI

c# - 列表框未绑定(bind)到 BindingList<T>

c# - 如何从反编译 .NET 程序集创建的 .resources 文件中提取图像?

c# - 从代码隐藏 (ASP.NET C#) 到 ASPX 中的图像概览的图像列表

c# - 将复杂数组从 Controller 传递到 View ASP.NET MVC

asp.net - 使用 ASP .Net 创建指向 S3 或 Cloudfront 托管内容的过期链接

build.gradle 中的 Android 数据绑定(bind) "enabled"已弃用

处理 "heavy"数据时的 WinForms UI 响应能力