如何将我的列表作为工具提示
How do I get my list in as a tooltip
在下面的代码中,我希望 GetChainDetails 中的 return 转到我在 GetChains 方法中有 "I WANT MY LIST HERE" 的位置。不确定如何完成或有什么其他方法可以做到这一点。
public static IEnumerable GetChains(int actGroupid, int dispid)
{
EEDBEntities db = new EEDBEntities();
var query = from c in db.Chains
where c.Activity_Basis.activity_group_id == actGroupid && c.Activity_Basis.discipline_id == dispid
select new
{
ChainID = c.ChainID,
ChainDesc = @"<span data-toggle=""tooltip"" title =""" + I WANT MY LIST HERE + @""">" + c.ChainID + "</span>"
};
return query.ToList();
}
public string GetChainDetails(string chainID)
{
string sStep = null;
var chainDetailList = from c in db.Chains_Detail
where c.chainID == chainID
orderby c.Order
select new
{
Order = c.Order,
Step = c.Step
};
foreach (var oItem in chainDetailList.ToList())
{
sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step;
}
return sStep;
}
你的方法public string GetChainDetails(string chainID) 不是静态的。也许这就是您出错的原因。将其设为静态并尝试 运行 代码。
public static string GetChainDetails(string chainID)
你也可以按照这个方法:
class X
{
public int Property1;
public int Property2;
public string ChainID;
public string MyListToolTipText;
}
class Y
{
public string ChainID;
public string ChainDesc;
}
还有你的主要代码
class Program
{
static void Main()
{
var myResult = GetChains(1, 1);
foreach (var result in myResult)
{
result.ChainDesc = GetChainDetails(result.ChainID);
}
//you can use either foreach or linq
//var m = myResult.Select(result => result = new Y { ChainID = result.ChainID, ChainDesc = GetChainDetails(result.ChainDesc) });
}
public static IEnumerable<Y> GetChains(int actGroupid, int dispid)
{
var Chains = new List<X>();
var query = from c in Chains
where c.Property1 == actGroupid && c.Property2 == dispid
select new Y
{
ChainID = c.ChainID,
ChainDesc = @"<span data-toggle=""tooltip"" title =""" + c.MyListToolTipText + @""">" + c.ChainID + "</span>"
};
return query.ToList<Y>();
}
public static string GetChainDetails(string chainID)
{
string sStep = null;
var chainDetailList = from c in db.Chains_Detail
where c.chainID == chainID
orderby c.Order
select new
{
Order = c.Order,
Step = c.Step
};
foreach (var oItem in chainDetailList.ToList())
{
sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step;
}
return sStep;
}
}
因此在调用 GetChains 之后,我正在修改每个成员 属性。
在下面的代码中,我希望 GetChainDetails 中的 return 转到我在 GetChains 方法中有 "I WANT MY LIST HERE" 的位置。不确定如何完成或有什么其他方法可以做到这一点。
public static IEnumerable GetChains(int actGroupid, int dispid)
{
EEDBEntities db = new EEDBEntities();
var query = from c in db.Chains
where c.Activity_Basis.activity_group_id == actGroupid && c.Activity_Basis.discipline_id == dispid
select new
{
ChainID = c.ChainID,
ChainDesc = @"<span data-toggle=""tooltip"" title =""" + I WANT MY LIST HERE + @""">" + c.ChainID + "</span>"
};
return query.ToList();
}
public string GetChainDetails(string chainID)
{
string sStep = null;
var chainDetailList = from c in db.Chains_Detail
where c.chainID == chainID
orderby c.Order
select new
{
Order = c.Order,
Step = c.Step
};
foreach (var oItem in chainDetailList.ToList())
{
sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step;
}
return sStep;
}
你的方法public string GetChainDetails(string chainID) 不是静态的。也许这就是您出错的原因。将其设为静态并尝试 运行 代码。
public static string GetChainDetails(string chainID)
你也可以按照这个方法:
class X
{
public int Property1;
public int Property2;
public string ChainID;
public string MyListToolTipText;
}
class Y
{
public string ChainID;
public string ChainDesc;
}
还有你的主要代码
class Program
{
static void Main()
{
var myResult = GetChains(1, 1);
foreach (var result in myResult)
{
result.ChainDesc = GetChainDetails(result.ChainID);
}
//you can use either foreach or linq
//var m = myResult.Select(result => result = new Y { ChainID = result.ChainID, ChainDesc = GetChainDetails(result.ChainDesc) });
}
public static IEnumerable<Y> GetChains(int actGroupid, int dispid)
{
var Chains = new List<X>();
var query = from c in Chains
where c.Property1 == actGroupid && c.Property2 == dispid
select new Y
{
ChainID = c.ChainID,
ChainDesc = @"<span data-toggle=""tooltip"" title =""" + c.MyListToolTipText + @""">" + c.ChainID + "</span>"
};
return query.ToList<Y>();
}
public static string GetChainDetails(string chainID)
{
string sStep = null;
var chainDetailList = from c in db.Chains_Detail
where c.chainID == chainID
orderby c.Order
select new
{
Order = c.Order,
Step = c.Step
};
foreach (var oItem in chainDetailList.ToList())
{
sStep = sStep + "\n" + oItem.Order + ": " + oItem.Step;
}
return sStep;
}
}
因此在调用 GetChains 之后,我正在修改每个成员 属性。