Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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# 需要中继器的帮助吗_C#_Asp.net - Fatal编程技术网

C# 需要中继器的帮助吗

C# 需要中继器的帮助吗,c#,asp.net,C#,Asp.net,这是我的中继器: <asp:Repeater ID="myRepeater" OnItemCommand="myRepeater_ItemCommand" runat="server" OnItemDataBound="myRepeater_OnItemDataBound"> <HeaderTemplate> <table width="99%" border="0" cellpadding="0" cellspacing="0">

这是我的中继器:

<asp:Repeater ID="myRepeater" OnItemCommand="myRepeater_ItemCommand" runat="server" OnItemDataBound="myRepeater_OnItemDataBound">
     <HeaderTemplate>
         <table width="99%" border="0" cellpadding="0" cellspacing="0">
             <tr class="lgrey">
                <td>Default</td>
             </tr>
     </HeaderTemplate>
     <ItemTemplate>
         <table>
             <tr>
                <td>
                    <asp:LinkButton ID="lnk1" Text="Make Default" CommandName="SetDefault" runat="server" Visible="True" CommandArgument='<%#Eval("UserID") %>' CausesValidation="false"></asp:LinkButton>
                    <asp:Label ID="label1" Text="Yes" runat="server" Visible="False"></asp:Label>
                </td>
             </tr>
     </ItemTemplate>
     <FooterTemplate>
         </table>
     </FooterTemplate>
</asp:Repeater>

违约
我想要的是当用户点击任何一个 repeater呈现的列表中的“lnk1”链接按钮, 该链接应替换为标签“label1”。。 i、 e.当用户点击“设置默认值”链接时,应将其替换为“是”标签

调用此方法
obj.SetDefaultAddress()正在设置数据库中的默认地址。。
问题是当中继器渲染时label1和lnk1的显示

发生的情况是,“设置默认”链接按钮和“是”标签都显示出来 在我的中继器内表格的“Default”列下

我想要一些代码,将检查我的数据库中的“IsDefault”值,并显示“makedefault”链接按钮

和相应的“是”标签。。。i、 e.如果数据库中的IsDefault值为真,则中继器中应显示“是”
否则“设置默认值”

您确定ItemCommand下的代码隐藏中的代码正在执行吗? 我只是将aspx文件中的CommandName从SetDefault更改为SetDefaultAddress,以与代码隐藏中的CommandName相匹配,它起作用了。

从何处开始

我认为导致您出现问题的原因是
SelectedItem
DefaultAddress
没有相互映射,因此当您单击按钮时,您将获得所选索引集,
OnItemDatabound
事件显示/隐藏您想要的内容,但当网格从数据库初始化时,未设置
SelectedItem


我不知道您的数据源是什么,而且其中的代码显然比您发布的代码还要多,但是如果您可以查看
myRepeater\u ItemDataBound
处理程序中的
e.Item.DataItem
,当地址为默认地址(
e.Item.ItemType…)或使用“selectedIndex”时,您可以将当前项目设置为选中计数器

我可能会从标记本身进行操作-这是假设您的数据源中有位/布尔类型的“IsDefault”列/属性,指示地址是默认的。因此,请使用以下标记:

...
<tr>
   <td>
       <asp:LinkButton ID="lnk1" Text="Make Default" CommandName="SetDefault" runat="server" Visible='<%# !Eval("IsDefault") %>' CommandArgument='<%#Eval("UserID") %>' CausesValidation="false"></asp:LinkButton>
       <asp:Label ID="label1" Text="Yes" runat="server" Visible='<%# !Eval("IsDefault") %>'></asp:Label>
    </td>
</tr>
...

我已经更正了…我错误地键入了..命令名确实匹配..它将地址设置为默认的DB!在您编辑的代码中,您正在使用obj.IsDefault,您是否尝试在调试模式下检查其值?调试器仅将IsDefault的值显示为false,这就是为什么在中继器中显示“设置默认值”链接的原因。下面的回答者说probelm与选定的索引有关。我该如何解决这个问题?Plz help..thnxYes我同意Kendrick的观点,无论何时刷新页面,selectedItem都将设置为-1。如果您告诉我一些关于您的数据源的信息,那么我可能会提供帮助,比如它返回的列是什么。数据源来自一个存储过程,它只是从UserAddress表中选择所有列,即地址ID、地址1、地址2、城市、州、电话、,IsDefaultData源来自一个存储过程,它只选择UserAddress表中的所有列。我需要在代码中更改什么?I如果我不使用所选索引,则标签不会更改为“是”,我丢失了:/I尝试了与标记中的完全相同的操作!不起作用:(你说我需要重新绑定repeater新状态…我该怎么做?在哪里?比如调用绑定repeater的方法?我该在哪里调用它?我已经在像这样的项命令事件中绑定repeater:-myRepeater.DataSource=GetAddress();myRepeater.DataBind();@Serenity,在标记中使用Visible=''时会发生什么?生成的html是什么样的-它生成Visible=“True/False”还是数据绑定表达式没有正确解析?表达式得到解析..它的计算结果为False这就是为什么“Make Default”链接按钮appears@Serenity,我希望您在尝试标记时已删除ItemDataBound事件,因为ItemDataBound将覆盖标记中的值。但无论如何,请参阅我的编辑,以了解如何通过ItemDataBound事件执行相同操作。
protected void myRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
           bllUsers obj = e.Item.DataItem as bllUsers;
           ((Label)e.Item.FindControl("ldefault")).Visible = obj.isDefault; 
           ((Button)e.Item.FindControl("btnMakeDefault")).Visible = ! obj.isDefault; 
        }
    }