Visual Web Developer [英] Visual Web Developer

查看:75
本文介绍了Visual Web Developer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到如果在与之关联的数据库表中有记录,则只能使用DetailsView控件。这是愚蠢的,或者我错过了什么。我进行了一次演练,当我完成时,我的页面上没有显示任何内容。然后我去了数据库并添加了几个记录,然后低了,看到我再次运行网页,它显示了我刚创建的记录。我还可以添加新记录,编辑和删除。

这真是太愚蠢了!我怎么能期望使用只有在数据库表中有记录才有效的控件?

我缺少什么?请帮助

解决方案

Hello Dmano,


< span style ="line-height:115%; font-size:10pt">


如上所述,你很困惑DetailsView控件,不用担心。我会告诉你如何在绑定数据库中没有数据时处理它。



有一点需要注意的是e当绑定到控件的数据源不包含任何记录时,mpty数据行显示在DetailsView控件中。但是,您可以使用EmptyDataTemplate属性为空数据行定义自己的自定义用户界面(UI)。要为空行指定自定义模板,请先放置< EmptyDataTemplate> DetailsView控件的开始和结束标记之间的标记。然后,您可以在开始和结束之间列出模板的内容< EmptyDataTemplate>标签。



以下是我写的相关代码,您可以参考它们来查看它是否有帮助。



< EmptyDataTemplate>


没有可用的数据。 请点击


< asp:LinkBut​​ton ID =" LinkBut​​ton1" RUNAT = QUOT;服务器" OnClick =" LinkBut​​ton1_Click"> here< / asp:LinkBut​​ton>


以插入新数据。


< / EmptyDataTemplate>



protected void LinkBut​​ton1_Click(object sender,EventArgs e)


{


this.DetailsView1 .ChangeMode(DetailsViewMode.Insert);
}



更多详情。您可以参考详细信息查看.EmptyDataTemplate属性


I've noticed that you can only use the DetailsView control if you have records in the database table it's associated with. This is stupid or I'm missing something. I followed a walkthrough and when I was finished nothing showed up on my page. I then went to the database and added a couple records then low and behold I ran the web page again and it showed me the records I had just created. I could also add new records, edit and delete.

This is really stupid! How on earth am I expected to use a control that only works if I have records in the database table?

What am I missing? Please help

解决方案

Hello Dmano,

 

As you mentioned above you are confused about the DetailsView control,do not worry.I will show you how to deal with it when no data is in the binded databse.

 

One thing to be aware of is that the empty data row is displayed in a DetailsView control when the data source that is bound to the control does not contain any records. But you can define your own custom user interface (UI) for the empty data row by using the EmptyDataTemplate property. To specify a custom template for the null row, first place <EmptyDataTemplate> tags between the opening and closing tags of the DetailsView control. You can then list the contents of the template between the opening and closing <EmptyDataTemplate> tags.

 

Here are the related codes I wrote,you may refer to them to see if it helps or not.

 

<EmptyDataTemplate>

        There is no data available.  Please click 

        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">here</asp:LinkButton>

         to insert new data.

</EmptyDataTemplate>

 

protected void LinkButton1_Click(object sender, EventArgs e)

    {

        this.DetailsView1.ChangeMode(DetailsViewMode.Insert);
   }


For more details.You could refer to DetailsView.EmptyDataTemplate Property.


这篇关于Visual Web Developer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆