简体   繁体   中英

trigger an eventhandler on postback c#

I am pretty new to c# programming. I have an issue that follows: I have a GridView on a web form, a DropDownList and a Label control. When i select a value from a DDL a Grid View is populated with rows from the database that equal the DDL condition(in my case DDL represent Countries, GV lists the Cities). When i delete the last City from a GV using a built in GV Delete function i would like to automatically write in a Label that there are no more Cities in selected Country. How can i achieve that? I tried to put

protected void GridView1_RowDeleted1(object sender, GridViewDeletedEventArgs e)
{
    if (GridView1.Rows.Count == 0)
    {
        LabelGrid.Text = "No more cities.";
    }
}

but it didn't work.

Thanks for your help

Consider using PreRender event, when that event runs the Row.Count property contains the correct value. (decremented after delete)

    protected void GridView1_PreRender(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count == 0)
        {
            LabelGrid.Text = "No more cities.";
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM