Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何更改Codebehind中ListView元素的值_Asp.net_Code Behind - Fatal编程技术网

Asp.net 如何更改Codebehind中ListView元素的值

Asp.net 如何更改Codebehind中ListView元素的值,asp.net,code-behind,Asp.net,Code Behind,我正在尝试使用Listview创建一个表,我使用的其中一个字段应该显示指向所显示数据的更详细视图的超链接,我希望通过在该项的ID上使用FindControl,然后将值更改为附加查询字符串的详细视图页面的超链接,问题是我不知道如何将该数据重新插入listview字段,该字段如下所示: <ItemTemplate> <td> <asp:Label ID

我正在尝试使用Listview创建一个表,我使用的其中一个字段应该显示指向所显示数据的更详细视图的超链接,我希望通过在该项的ID上使用
FindControl
,然后将值更改为附加查询字符串的详细视图页面的超链接,问题是我不知道如何将该数据重新插入listview字段,该字段如下所示:

                    <ItemTemplate>
                    <td>
                    <asp:Label ID="ViewLinkLabel" runat="server" 
                        Text='[insert Link Here]' />
                    </td>
                    </ItemTemplate>
<ItemTemplate>
  <td>
    <asp:HyperLink ID="ViewLinkLabel" runat="server" Text="More details"
         NavigateUrl='<%# string.Format("~/DetailPage.aspx?ID={0}", Eval("RecordID")) %>' />
  </td> 
</ItemTemplate>

请记住,我仍然是ASP.net的业余爱好者,如果有一个我不知道的更容易做到的方法,那么这一切看起来都太复杂了


谢谢

将标签更改为超链接,并使用listview上的OnItemDataBound事件修改元素:类似

  protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)                  
  {
        try
        {
            HyperLink ViewLinkLabel = (HyperLink)e.Item.FindControl("ViewLinkLabel");
            lnkEvent.NavigateUrl += "http://required.url;
        }
        catch
        {

        }
    }

想了解更多细节,你在这里犯了一些错误。首先,如果要执行此操作,您需要使用



它们是在asp.NET3.5出现之前编写的,因此不涉及listview控件,但它们将向您解释如何设置master/detail以及数据绑定语法的工作原理。如果您阅读了该数据访问系列中的前25个教程,那么您将对许多asp.net功能的工作原理有一个非常深入的了解。它使用的数据访问技术有点过时,但很容易开始使用。

我没有足够的声誉留下评论或编辑帖子,但Richard Harrison帖子中的代码示例存在一些问题:

  protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)                  
  {
        try
        {
            HyperLink ViewLinkLabel = (HyperLink)e.Item.FindControl("ViewLinkLabel");
            ViewLinkLabel.NavigateUrl = "http://www.example.com/";
        }
        catch
        {

        }
    }
理想情况下,在使用ViewLinkLabel之前,还应该检查它是否为null

这也是假定ViewLinkLabel控件是超链接,但在问题中,这实际上是一个标签控件