'发布'在数据库中时一个字段 ,前台代码
<asp:GridView ID="GridView1" CellSpacing="7" Width="780px" runat="server" CellPadding="6"
AutoGenerateColumns="False" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onrowcancelingedit="GridView1_RowCancelingEdit"
EnableModelValidation="True" onrowdeleting="GridView1_RowDeleting"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="region" HeaderText="区域" ReadOnly="true" />
<asp:BoundField DataField="meetingtime" HeaderText="时间" />
<asp:BoundField DataField="city" HeaderText="城市" />
<asp:BoundField DataField="sumcount" HeaderText="总数" />
<asp:BoundField DataField="address" HeaderText="具体地址" />
<%-- <asp:CommandField HeaderText="修改" ShowEditButton="true" />--%>
<asp:TemplateField HeaderText="更新">
<ItemTemplate>
<a οnclick='alterLocation("<%#Eval("LocationID")%>");' href="#">更新</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lkBtnDel" runat="server" CausesValidation="False" CommandArgument='<%#Eval("locationID")%>' OnClientClick="return confirm('您确认要删除吗?');" CommandName="Delete" Text="Delete">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="发布" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lkBtnPublish" runat="server" CausesValidation="False" CommandArgument='<%#Eval("locationID")%>' CommandName="Publish" Text='<%# GetStr(DataBinder.Eval(Container.DataItem, "IsPublish").ToString()) %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Height="25px" Font-Bold="false" BackColor="#dce4ec" />
<RowStyle Height="25px" BackColor="#FFFFFF" />
<FooterStyle Height="25px" />
</asp:GridView>
后台:
public string GetStr(string str)
{
if (str == "1")
{
return "取消发布";
}
else
{
return "发布";
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string locationID = e.CommandArgument.ToString();
Location location = dal.FindLocationByLoID1(locationID);
GridViewRow row = ((Control)e.CommandSource).NamingContainer as GridViewRow;
LinkButton lkbtn = (LinkButton)row.FindControl("lkBtnPublish");
switch (e.CommandName)
{
case "Publish":
{
if (lkbtn.Text == "发布")
{
location.IsPublish = "1";
dal.UpdateLocation(location);
Response.Redirect("LocationList.aspx?courseID="+courseID);
}
else
{
location.IsPublish = "0";
dal.UpdateLocation(location);
Response.Redirect("LocationList.aspx?courseID=" + courseID);
}
break;
}
}
}