本文介绍了响应中继的ItemTemplate里面的按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经删除了datasouce,只是有的DataBind(),那么我的网页仍吹刷新页面,而不是在编辑模式。

我所试图做的是当编辑按钮,用户点击即可使其内嵌编辑中继一行。

END更新

onItemCommand我已经添加的DataBind()

  rpt.DataSource = mydatasource;
rpt.DataBind();

后,我做的,我的网页是不是在编辑模式下,它吹走和everyting被刷新
我在Page_Load中

 如果(!的IsPostBack)
{
   rpt.DataSource = mydatasource;
    rpt.DataBind();}

末更新

我用中继很多次都没有问题,但事情是怎么回事。我有一个直放站和我订阅ItemDataBound事件,但是当我点击该按钮(这是我的ItemTemplate直放站里面一个LinkBut​​ton)它不会转到的ItemDataBound

 < ASP:直放站ID =RPT=服务器OnItemCommand =rpt_OnItemCommandOnItemDataBound =rpt_OnItemDataBound>
    <&ItemTemplate中GT;
        <立GT;
            < ASP:标签ID =标签=服务器/>
            < ASP:LinkBut​​ton的ID =LinkBut​​ton1=服务器的CommandName =编辑CommandArgument ='<%#的eval(身份识别码)%GT;'
                文字='<%#的eval(标题)%GT;' />
        < /李>
    < / ItemTemplate中>
< / ASP:直放站>
    保护无效rpt_OnItemCommand(对象源,RepeaterCommandEventArgs E)
          {
              如果(e.CommandName ==删除)
              {
                  //Data.Contacts.RemoveAt(e.Item.ItemIndex);
              }
              否则,如果(e.CommandName ==编辑)
              {
                  EditIndex = e.Item.ItemIndex;
              }
              否则,如果(e.CommandName ==拯救)
              {
                  //
              }           }
保护无效rpt_OnItemDataBound(对象发件人,RepeaterItemEventArgs E)
{
     如果(e.Item.ItemType == || ListItemType.Item == e.Item.ItemType ListItemType.AlternatingItem)
      {        如果(e.Item.ItemIndex == EditIndex)
        {
          //从未到该行....上LinkBut​​ton的用户点击后        }      }
}


解决方案

不知道如果这能帮助,但你必须先调用DataBind()用于为OnItemDataBound事件触发。另外我的猜测是您要设置EditIndex在OnItemCommand,然后在OnDataBind事件中使用的值。然后,事件触发的顺序OnItemDataBound OnItemCommand在这种情况下让Ed​​itIndex不会是正确的呢。

添加rpt.DataBind到OnItemCommand。这workded当我试图从code,注意你,如果你不使用!的IsPostBack原始数据绑定有约束力的两倍。

  rpt.DataSource =串;  如果(!的IsPostBack)
  {
       rpt.DataBind();
  } 保护无效rpt_OnItemCommand(对象源,RepeaterCommandEventArgs E)
 {
      如果(e.CommandName ==删除)
      {
          //Data.Contacts.RemoveAt(e.Item.ItemIndex);
      }
      否则,如果(e.CommandName ==编辑)
      {
          EditIndex = e.Item.ItemIndex;
      }
      否则,如果(e.CommandName ==拯救)
      {
          //
      }     rpt.DataBind();   }

so i have removed the datasouce and just have DataBind() then my page is still blowing and refreshing the page and not in a EDIT mode.

what i am trying to do is when the user click on Edit button then make it inline editing the repeater row.

END UPDATE

onItemCommand i have added DataBind()

rpt.DataSource = mydatasource; 
rpt.DataBind();

after i do that my page is not in edit mode and it blow away and everyting is refreshed i have on page_load

if (!IsPostBack) 
{
   rpt.DataSource = mydatasource; 
    rpt.DataBind();

}

end update

I've used repeaters many times without problems but something is going on here. I have a repeater and I'm subscribing to the itemDatabound event, But when i click the button (which is a linkbutton inside my repeater itemtemplate) it does not go to the ItemDataBound

<asp:Repeater ID="rpt" runat="server" OnItemCommand="rpt_OnItemCommand" OnItemDataBound="rpt_OnItemDataBound">
    <ItemTemplate>
        <li>
            <asp:Label ID="Label" runat="server" />
            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit" CommandArgument='<%# Eval("MyID") %>'
                Text='<%# Eval("Title") %>' />
        </li>
    </ItemTemplate>
</asp:Repeater>


    protected void rpt_OnItemCommand(object source, RepeaterCommandEventArgs e)
          {
              if (e.CommandName == "delete")
              {
                  //Data.Contacts.RemoveAt(e.Item.ItemIndex);
              }
              else if (e.CommandName == "edit")
              {
                  EditIndex = e.Item.ItemIndex;
              }
              else if (e.CommandName == "save")
              {
                  //          
              }

           }


protected void rpt_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {

        if (e.Item.ItemIndex == EditIndex)
        {
          // never come to this line.... after the user click on LinkButton

        }

      }
} 
解决方案

Don't know if this helps but you must call DataBind() in order for for the OnItemDataBound event to fire. Also my guess is you are trying to set the EditIndex in the OnItemCommand and then use the value in the OnDataBind event. The events fire in the order OnItemDataBound then OnItemCommand so the EditIndex wouldn't be correct anyway in that situation.

Add rpt.DataBind to the OnItemCommand. This workded when I tried it from your code, NOTE that you will be binding twice if you aren't using !IsPostBack for original data bind.

  rpt.DataSource = strings;

  if (!IsPostBack)
  {
       rpt.DataBind();
  }

 protected void rpt_OnItemCommand(object source, RepeaterCommandEventArgs e)
 {
      if (e.CommandName == "delete")
      {
          //Data.Contacts.RemoveAt(e.Item.ItemIndex);
      }
      else if (e.CommandName == "edit")
      {
          EditIndex = e.Item.ItemIndex;
      }
      else if (e.CommandName == "save")
      {
          //          
      }

     rpt.DataBind();

   }

这篇关于响应中继的ItemTemplate里面的按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:46