我有一个GridView,它在最初加载时使用查询字符串来填充。如果查询字符串中的ID是新ID,则用户根本不会看到GridView;但是用户可以选择单击“插入”按钮,然后GridView将显示,他们应该能够插入新数据。在用户插入新项目之后,用户将单击另一个按钮以将电子邮件发送到某个组。我的问题是,有时用户会在网格视图中添加新项目之前发送电子邮件。我想确保GridView显示在页面上并且至少有一个项目,然后用户应该能够将电子邮件发送到任何组。有没有办法检查GridView是否显示并且其中至少有一个项目?
asp:GridView ID="GV_Action" runat="server" AutoGenerateColumns="False" CellPadding="2"
DataKeyNames="ID" ForeColor="Black" GridLines="None" OnRowCancelingEdit="GV_Action_RowCancelingEdit"
OnRowDeleting="GV_Action_RowDeleting" OnRowEditing="GV_Action_RowEditing"
OnRowUpdating="GV_Action_RowUpdating" Width="900px"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px">
<FooterStyle BackColor="Tan" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" >
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="RCA ID">
<EditItemTemplate>
<asp:TextBox ID="txtPostID" runat="server" Width="0px" ReadOnly="true"
text='<%# Request.QueryString["Post_ID"] %>' Height="0px"></asp:TextBox>
</EditItemTemplate>
</Columns>
<RowStyle HorizontalAlign="Left" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Left" />
<HeaderStyle BackColor="Tan" Font-Bold="True" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
这是我的绑定代码:
private void BindData_Action()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT ID, name, Assigned_To, Target_Date, Ticket_Change_Control_Number FROM MyTable WHERE ID = '" + Request.QueryString["ID"] + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
GV_Action.DataSource = dt;
GV_Action.DataBind();
}