Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
C# 在loggedin模板的listview控件中设置标签文本_C#_Asp.net - Fatal编程技术网

C# 在loggedin模板的listview控件中设置标签文本

C# 在loggedin模板的listview控件中设置标签文本,c#,asp.net,C#,Asp.net,我需要设置一个标签文本,这是listview和listview是在登录模板。 我无法设置标签的值。下面是代码 ListView ListView1 = (ListView)LoginView.FindControl("ListView1"); for (int i = 0; i < ListView1.Controls.Count; i++) { Label someLabel = (Label)ListView1.Controls[i].FindControl("nItemsI

我需要设置一个标签文本,这是listview和listview是在登录模板。 我无法设置标签的值。下面是代码

ListView ListView1 = (ListView)LoginView.FindControl("ListView1");

for (int i = 0; i < ListView1.Controls.Count; i++)
{
    Label someLabel = (Label)ListView1.Controls[i].FindControl("nItemsId");
    if (someLabel != null)
        someLabel.Text = dt.Rows.Count.ToString();
}
ListView ListView1=(ListView)LoginView.FindControl(“ListView1”);
对于(int i=0;i
所以我认为您需要使用事件来实现这一点

protected void LV_ItemCreated(object sender, ListViewItemEventArgs e)
{
  // Retrieve the current item.
   ListViewItem item = e.Item;

  // Verify if the item is a data item.
  if (item.ItemType == ListViewItemType.DataItem)
  {
    Label someLabel = (Label)ListView1.Controls[i].FindControl("nItemsId");
    if (someLabel != null)
        someLabel.Text = dt.Rows.Count.ToString();
  }
}
要使用它,请将标记更改为这样声明eventHandler

<asp:ListView OnItemCreated="LV_ItemCreated" />


您将在加载页面上绑定列表视图的时间。在listview中创建项目时会自动触发此事件。是的,但是我在_Select_项目上有另一个受保护的方法void(对象发送方,ListViewCommandEventArgs e){}。我需要调用您在此方法中建议的上述方法..如何发送ListViewItemEventArgs参数?您不需要在另一个处理程序中调用此处理程序。在ListView中创建项目时,此处理程序将接管所有内容。我们在这里定义了当在其内部创建项时,它应该做什么?我将SQL数据绑定到ListView,并且每行都有一些按钮,每当单击按钮时,调用选择项,然后我需要更新布局模板中的标签。因此,您可以在选择项事件处理程序上执行相同的操作。在该处理程序中查找控件并设置值。