CommandArgument='<%#Eval("Roleid") %>'/>
protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "updateState")
{
LinkButton Lb = (LinkButton)sender;
Lb.Text = "禁用";
} }
LinkButton 可以触发CommandName ,Button ,imgeButon 不能触发
二: <asp:ButtonField CommandName="ShowTeam" HeaderText="团队信息"
Text="团队信息" />
protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "updateState")
{
Page.Alert("updateState");
}
if (e.CommandName == "ShowTeam")
{
Page.Alert(e.CommandArgument.ToString()); // e.CommandArgument得到当前行 的索引,可
int ClientID = Convert.ToInt32(ClientGridview.DataKeys[index].Value.ToString());
得到相应的 数据
((LinkButton)e.CommandSource).Text = "禁用"; 由e.CommandSource得到事件源,也就是LinkButton, 就可以操作这个 linkButton 的属性了 }
}
protected void GVrole_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "updateState")
if (((LinkButton)e.CommandSource).Text.ToString() == "禁用")
{
((LinkButton)e.CommandSource).Text="可用";
}
else
三:通过onCommand 命令配置事件
<asp:Button ID="garbage" OnCommand="garbage" OnClientClick="return confirm('确定设为垃圾问题吗?');" runat="server" Text="垃圾处理" visible="false " CommandName="garbage" CommandArgument='<%#Eval("ID") %>'/>
protected void Refer(object sender, CommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument);
using (DataClassesDataContext db = new DataClassesDataContext())
{
var QuSupport = db.QuestionSupport.FirstOrDefault(q => q.ID == id);
if (QuSupport != null)
{
content.Text = QuSupport.SupportContent; //得到Content的内容
QuSupport.IsRefereed = true; //设置引用为真
try
{
db.SubmitChanges();
}
catch (Exception)
{
throw;
}
}
}
}