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
C# 在asp:repeater Eval中如何通过索引而不是列名获取值_C#_Asp.net_Repeater_Datarow_Datatable.select - Fatal编程技术网

C# 在asp:repeater Eval中如何通过索引而不是列名获取值

C# 在asp:repeater Eval中如何通过索引而不是列名获取值,c#,asp.net,repeater,datarow,datatable.select,C#,Asp.net,Repeater,Datarow,Datatable.select,我尝试使用列索引获取数据,而不是使用表达式或我的repeater控件中的任何其他方式获取列名。 这是我的密码: 第页: <asp:Repeater ID="rptrHeatingNavien" runat="server"> <ItemTemplate> <li class="icon-font"><a href="/Products/?Id=<%#Eval('get-data-by-index[0]')%>>&

我尝试使用列索引获取数据,而不是使用表达式或我的repeater控件中的任何其他方式获取列名。 这是我的密码:

第页:

<asp:Repeater ID="rptrHeatingNavien" runat="server">
    <ItemTemplate>
        <li class="icon-font"><a href="/Products/?Id=<%#Eval('get-data-by-index[0]')%>><a><%#Eval('get-data-by-index[1]')%></a></li>
    </ItemTemplate>
    </asp:Repeater>

这里的问题是,出于某种原因,我非常乐意知道为什么,我不能为绑定到repeater控件的行使用列名。我仔细检查了它们是否包含数据。因此,摆在我面前的唯一解决方案是通过它们的列索引获取它们,我不知道该怎么做。有什么解决方案吗?

假设您绑定的是SuperItem对象集合SuperItem type支持基于索引的访问,您可以处理ItemDataBound事件:


你的代码是如何编译的?sqlDaS.Fillds;应该是sqlDa.Fillds;这是一个打字错误:。抱歉!!!
string connectionString = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionString);
SqlDataAdapter sqlDa = new SqlDataAdapter("SELECT * FROM Products", sqlCon);
DataSet ds = new DataSet();
sqlDa.Fill(ds);
rptr.DataSource = dsSideMenu.Tables[0].Select("category = '1-1-1'");
rptr.DataBind();
<asp:Repeater ID="rptrHeatingNavien" runat="server" OnItemDataBound="rptrHeatingNavien_ItemDataBound">
    <ItemTemplate>
        <li class="icon-font">
            <asp:HyperLink runat="server" ID="productLink" />
    </ItemTemplate>
</asp:Repeater>
protected void rptrHeatingNavien_ItemDataBound(object sender, EventArgs e)
{
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var item = (SuperItem) e.Item.DataItem;
        var link = (HyperLink) e.Item.FindControl("productLink");
        link.NavigateUrl = string.Format("/Products/?Id={0}", item[0].ToString());
        link.Text = item[1].ToString();
    }
}