Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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中的动态s id_Asp.net - Fatal编程技术网

如何设置控件';asp.net中的动态s id

如何设置控件';asp.net中的动态s id,asp.net,Asp.net,如何使用Eval方法动态设置id,并将id从sql数据库设置为控制器,如下所示 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="articlesqlfetch"> <ItemTemplate> <strong > <%# Eval("title") %> </strong> <br> <

如何使用Eval方法动态设置id,并将id从sql数据库设置为控制器,如下所示

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="articlesqlfetch">
      <ItemTemplate>
           <strong > <%# Eval("title") %>  </strong> 
               <br>
<-! this is the line   ->
           <asp:HyperLink ID="_<%# Eval("id") %>" runat="server">قراءة المزيد</asp:HyperLink>         
      </ItemTemplate>   



قراءة المزيد
执行此操作时,会给我一个解析器错误

不允许使用
Eval()
提供动态生成的ID,因为您无法绑定到服务器控件的ID属性,因此此代码错误:

<asp:HyperLink ID="_<%# Eval("id") %>" runat="server">some text</asp:HyperLink>
代码隐藏

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    HyperLink hyperlink = e.Item.FindControl("Hyperlink1") as HyperLink;
    if (hyperlink != null) 
    {
        hyperlink.ID = "_" + (e.Item.ItemIndex + 1).ToString(); // set ID from bound data
        hyperlink.ClientIDMode = ClientIDMode.Static;
        hyperlink.NavigateUrl = "some/uri/here"; // optional

        // other stuff
    }
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    HyperLink hyperlink = e.Item.FindControl("Hyperlink1") as HyperLink;
    if (hyperlink != null) 
    {
        hyperlink.ID = "_" + (e.Item.ItemIndex + 1).ToString(); // set ID from bound data
        hyperlink.ClientIDMode = ClientIDMode.Static;
        hyperlink.NavigateUrl = "some/uri/here"; // optional

        // other stuff
    }
}