Show message on click of a button in ASP.net
I have a Gridview, a label and a Button in ASP.net. If the total number of records in the g开发者_如何学Goridview is more than 500 and if the user clicks on the button, a message "You cannot print more than 500 records at one time".
How can I do this in ASP.net. If it is less than 500 it is currently generating a PDF.
Thanks
Like this:
if (grid.Rows.Count > 500) {
label.Text = "You cannot print more than 500 records at one time";
} else {
//Export a PDF
}
If this doesn't answer your question, please provide more detail.
I think you'd want something like this in the code behind file:
protected void Button_Click(object sender, EventArgs e)
{
if (this.myGridView.Rows.Count > 500)
{
this.myLabel.Text = "You can not print more than 500 records";
}
else
{
// Print the PDF
}
}
Now on the ASP side of things you hook these up like so:
<asp:button id="myButton" onclick="Button_Click" runat="server" text="Print PDF of Grid" />
When you get your records, examine the count of the records. Then, if it's more than 500, add a javascript alert to the button like this:
If records.Count > 500 Then
btnPrint.Attributes("onclick") = "alert('You cannot print more than 500 records at one time.'); return false;"
Else
btnPrint.Attributes("onclick") = ""
End If
精彩评论