日期:2014-05-18  浏览次数:20359 次

请大家帮我看看这行代码,为什么Datagrid的模板列这样写不对?
<asp:TemplateColumn   HeaderText= "编辑 "> <HeaderStyle   HorizontalAlign= "Center "   Width= "50px "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
<ItemTemplate>
<a   href= "VT_Visit_Item.aspx?ID={1}&Type={2}&Action=Add "> 编辑 </a>
</ItemTemplate> </asp:TemplateColumn>

编辑的链接地址VT_Visit_Item.aspx?ID={1}&Type={2}&Action=Add
没有取得第一行与第二列的值。

第一次学这种写法,见笑了。

------解决方案--------------------
<a href= "VT_Visit_Item.aspx?ID={1}&Type={2}&Action=Add "> 编辑 </a>

》》》

<a href= ' <%# String.Format( "VT_Visit_Item.aspx?ID={0}&Type={1}&Action=Add ", Eval( "字段1 "), Eval( "字段2 ")) %> '> 编辑 </a>
------解决方案--------------------
需要在ItemDataBind的时候对数据进行处理

aspx:
<ItemTemplate>
<asp:Label id=lblLink ...>
</ItemTemplate>

cs:
ItemDataBind(...)
{
((Label)e.Item.FindControl( "lblLink ")).InnerHtml
= " <a href=\ "VT_Visit_Item.aspx?ID= "+e.item.cells[0].text+ "&Type= "+e.item.cells[1].text+ "&Action=Add\ "> 编辑 </a> ";

}
------解决方案--------------------
<a href= "VT_Visit_Item.aspx?ID={1}&Type={2}&Action=Add "> 编辑 </a>
============================================================
<a href= ' <%# "VT_Visit_Item.aspx?ID= " + Eval( "id ") + "&Type= " + Eval( "Type ")+ "&Action=Add " %> ' > 编辑 </a>