请教在GridView里的Button怎么接受参数?
我用GridView(ID=MyGridView)接受一个参数用户ID(UserID)来显示当前用户所经营的商品,然后在MyGridView加一列Button,分别对应每一行商品信息,Button用来删除这个商品,点击Button即可删除这个商品.请问Button怎么识别每一行的商品ID(GoodsID),GoodsID不连续.
数据库里3张表 分别是User表 Goods表 UserToGoods表.
------解决方案--------------------直接使用按钮比较麻烦,可以用另一种办法,如果你想使用有图片的按钮,可以直接加上一张图片,然后使用超连来跳转,如:
<a href= "edit.aspx?id= <%# Eval( "ID ") %> "> <img src= "images/button_modify.gif " alt= "修改 " width= "61 " height= "20 " border= "0 " /> </a>
这样看上去就是一个图片按钮了
------解决方案--------------------给你个实例:
前台:
<asp:GridView ID= "gvCourse " DataKeyNames= "CourseNo " runat= "server " AutoGenerateColumns= "False " BackColor= "White "
BorderColor= "#DEDFDE " BorderStyle= "None " BorderWidth= "1px " CellPadding= "4 " ForeColor= "Black "
GridLines= "Vertical " Width= "100% " AllowPaging= "True " OnRowEditing= "gvCourse_RowEditing " OnRowDeleting= "gvCourse_RowDeleting " OnRowCancelingEdit= "gvCourse_RowCancelingEdit " OnRowUpdating= "gvCourse_RowUpdating ">
<FooterStyle BackColor= "#CCCC99 " />
<Columns>
<asp:BoundField DataField= "CourseName " HeaderText= "课程名称 " >
<ItemStyle Width= "100px " />
</asp:BoundField>
<asp:BoundField DataField= "Memo " HeaderText= "备注 " />
<asp:CommandField CancelText= "取消 " DeleteText= "删除 " EditText= "编辑 " ShowEditButton= "True "
UpdateText= "更新 " CausesValidation= "False ">
<ItemStyle HorizontalAlign= "Center " Width= "80px " />
</asp:CommandField>
<asp:TemplateField>
<ItemStyle HorizontalAlign= "Center " Width= "40px " />
<ItemTemplate>
<asp:LinkButton ID= "btnDelete " runat= "server " OnClientClick= "return confirm( '严重警告!删除课程将删除与该课程有关的所有信息,是否继续? '); "
CommandName= "Delete " CausesValidation= "False "> 删除 </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor= "#F7F7DE " />
<SelectedRowStyle BackColor= "#CE5D5A " Font-Bold= "True " ForeColor= "White " />
<PagerStyle BackColor= "#F7F7DE " ForeColor= "Black " HorizontalAlign= "Right " />
<HeaderStyle BackColor= "#6B696B " Font-Bold= "True " ForeColor= "White " />
<AlternatingRowStyle BackColor= "White " />
<PagerSettings Visible= "False " />
</asp:GridView>