asp.net中如何数据库每一行中的内容读取到gridview后,也是行显示,我在每一行后面添加了一个按钮
4个回答
展开全部
用模版,或编辑资料行选择ButtonField按钮,或CommandFiled里面的几个功能按钮都可以
下面是ButtonField的例子
<asp:GridView ID="GV2" runat="server" CellPadding="4" CssClass="style23"
ForeColor="#333333" GridLines="None" onrowcommand="GV2_RowCommand"
onrowdeleting="GV2_RowDeleting"
onselectedindexchanged="GV2_SelectedIndexChanged" PageSize="5"
Width="100%">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="PASS" Text="通过" />
<asp:ButtonField CommandName="delete" Text="删除" />
</Columns>
<EditRowStyle BackColor="#CC33FF" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
CssClass="Freezing" HorizontalAlign="Left" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" CssClass="ms-formlabel DataGridFixedHeader" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FF99FF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
后台
protected void GV2_RowCommand(object sender, GridViewCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument); //找到主键id
string USERID = this.GV2.DataKeys[id].Value.ToString(); //找到主键值
if (e.CommandName == "PASS")// 找到名称
{
string sql = " insert into account_user_t select * from account_user_t_new where userid='" + USERID + "' ";
MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sql);
string sqldelete = " delete from account_user_t_new where userid='" + USERID + "' ";
MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sqldelete);
PublicFun.PublicFunction.showMsg(this, "已经通过注册");
//自己的逻辑
}
else if (e.CommandName == "delete")
{
string sql = "delete from account_user_t_new where userId='" + USERID + "' ";
MySqlHelper.ExecuteNonQuery(PublicFun.PublicFunction.GetDBconstr("ce_manage_db"), sql);
PublicFun.PublicFunction.showMsg(this, "已删除此注册用户:" + USERID + " ");
}
BoundList2();
Newapp = "";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接在gridview后边加一模板列,添加按钮就是了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
运用模板列就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询