我想做成这样的效果:上面一行显示用户的姓名,联系方式,投票按钮,下面一行显示用户的建议。用Datagrid绑定。
我现在的问题是只能在投票按钮的位置加一个Button,不知道怎样取得此文章的ID。
以前的绑定不用模版知道怎样做,现在这种不知道怎样了。
<asp:DataGrid id="DataGridTip" style="Z-INDEX: 101; LEFT: 88px; POSITION: absolute; TOP: 96px"
runat="server" AutoGenerateColumns="False" Width="312px" PageSize="3" AllowPaging="True">
<Columns>
<asp:BoundColumn Visible="False" DataField="ID" HeaderText="ID"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face=宋体>
<TABLE id=table1 cellSpacing=1 width=600 border=0>
<TR>
<TD width="25%" bgColor=#f0f0f0>姓名:</TD>
<TD width="25%" bgColor=#f0f0f0>联系方式:</TD>
<TD width="25%" bgColor=#f0f0f0>当前票数:</TD>
<TD width="25%" bgColor=#f0f0f0>在此需要一个投票按钮</TD></TR>
<TR>
<TD width="75%" bgColor=#f0f0f0 colSpan=4>内容:<%# DataBinder.Eval(Container, "DataItem.Content") %><BR></TD></TR>
<TR>
<TD width="75%" colSpan=4 height=20></TD></TR></TABLE></FONT>
</ItemTemplate>
</asp:TemplateColumn>
</Columns><PagerStyle Mode="NumericPages">
</PagerStyle></asp:DataGrid>

解决方案 »

  1.   

    或者把ID帮定到Button的CommandArgument属性中
      

  2.   

    在按钮上加上onclick事件
    onclick = "show('<%#DataBinder.Eval(Contianer.DataItem,"ID"%>')"
    show是javascript脚本
      

  3.   

    在绑定onclick事件的时候就可以!
    例:datagrid1_itemdatabound中
    Button btn=(Button)e.Item.Cells[0].Controls[1];  //代表button列
    string str=e.Item.Cells[2].Text;  //代表id列
    btn.Attributes.Add("onclick","javascript:alert(" + str + ");");
      

  4.   

    楼主你的问题是什么?是不能获取ID,还是在BUTTON里不知道怎么传ID参数?
    我想大概是后者。楼上的说了很多方法,我没有一一试过。如果还不行。你可以不要使用BUTTON,使用链接也可以。点击直接到一个提交页面,把ID,传过去,然后更新数据库,再自动关闭页面(同时可以把更新是否成功的信息返回到当前页)。比如"<a herf=submit.aspx?id=>"+e.cells[0].text+" target=_blank>投票</a>"