我有一个简单的webform,其中on load event我在gridview中绑定数据,然后我有一个搜索字段,用户搜索特定记录但按钮需要点击两次才能得到结果。我在页面上添加和删除按钮,但不需要单击两次。 请让我知道这个问题。
这是我的page_load事件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
uname = (string)(Session["username"]);
BtnUpdate.Enabled = false;
BindDropDown();
BindGrid();
}
}
这是我的搜索功能。
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable dt1 = BindGrid();
DataView dv = new DataView(dt1);
string SearchExpression = null;
if (!String.IsNullOrEmpty(txtsearch.Text))
{
SearchExpression = string.Format("'{0}'",txtsearch.Text.Trim());
dt1.DefaultView.RowFilter = "Convert(FLAG_CODE, 'System.String') LIKE '" + txtsearch.Text + "%'";
grdDetails.DataSource = dt1;
grdDetails.DataBind();
int count = grdDetails.Rows.Count;
lblRecordsCount.Text = count.ToString();
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Please enter flag code');", true);
}
}
aspx代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Surviellance/Surveillance.master" AutoEventWireup="true" CodeFile="GSMFlagMaster.aspx.cs" Inherits="Surviellance_GSMMaker" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link rel="Stylesheet" href="../Styles/style.css" type="text/css" />
<link rel="stylesheet" href="../Styles/StyleSheet.css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BodyContentPlaceHolder" runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="divContainermaster">
<fieldset style="border-bottom-style: solid; border-left-style: solid; border-right-style: solid; border-top-style: solid; border-top-width: 3px; border-color: #0071ad; height: auto">
<legend style="background-color: #0071ad; border-radius: 10px; font-size: 14px; padding: 5px; color: white; font-family: open_sans_condensedbold,arail;"><b>GSM Master Details:</b></legend>
<center>
<table style="width: 75%;">
<tr>
<td class="tdtext">
<asp:Label ID="lblFlagCode" runat="server" Text="Flag Code"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtBoxFlagCode" runat="server" ReadOnly="True" Width="150px"></asp:TextBox>
</td>
<td class="tdtext">
<asp:Label ID="lblEffectFrom" runat="server" Text="Effective from"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEffectiveFrom" runat="server" ReadOnly="True" Width="150px"></asp:TextBox>
</td>
<td class="tdtext">
<asp:Label ID="lblMonthTrade" runat="server" Text="Monthly Trading"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkMonthTrade" runat="server" />
</td>
</tr>
<tr>
<td class="tdtext">
<asp:Label ID="lblStatus" runat="server" Text="Status"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlStatus" runat="server" ForeColor="White" Width="150px" BackColor="#0071ad">
<asp:ListItem Value="---select---" Selected="False">---Select---</asp:ListItem>
<asp:ListItem Value="Active">Active</asp:ListItem>
<asp:ListItem Value="Inactive">Inactive</asp:ListItem>
</asp:DropDownList>
</td>
<td class="tdtext">
<asp:Label ID="lblEffectTo" runat="server" Text="Effective to"></asp:Label></td>
<td class="auto-style3">
<asp:TextBox ID="txtEffectiveTo" runat="server" ReadOnly="True" Width="150px"></asp:TextBox>
</td>
<td class="tdtext">
<asp:Label ID="lblWeekTrade" runat="server" Text="Weekly Trading"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkWeekTrade" runat="server" />
</td>
</tr>
<tr>
<td class="tdtext">
<asp:Label ID="lblASD" runat="server" Text="ASD per"></asp:Label></td>
<td>
<asp:DropDownList ID="ddlASDPer" runat="server" AppendDataBoundItems="true" ForeColor="White" Width="150px" BackColor="#0071ad">
<asp:ListItem Value="---select---" Selected="False">---Select---</asp:ListItem>
</asp:DropDownList>
</td>
<td class="tdtext">
<asp:Label ID="lblFlagDes" runat="server" Text="Flag Description"></asp:Label></td>
<td>
<asp:TextBox ID="txtBoxFlagDes" TextMode="MultiLine" runat="server" MaxLength="30" Width="150px"></asp:TextBox>
</td>
<td class="tdtext">
<asp:Label ID="lblTtoT" runat="server" Text="T to T Flag"></asp:Label>
</td>
<td>
<asp:CheckBox ID="chkTtoT" runat="server" Checked="True" />
</td>
</tr>
</table>
<br />
<table style="width: 75%; text-align: center">
<tr>
<td>
<asp:Button ID="BtnAdd" class="button" runat="server" Text="Add" OnClick="BtnAdd_Click" />
<asp:Button ID="BtnView" class="button" runat="server" Text="View" OnClick="BtnView_Click" />
<asp:Button ID="BtnUpdate" class="button" runat="server" Text="Update" OnClick="BtnUpdate_Click" />
<asp:Button ID="BtnClear" class="button" runat="server" Text="Clear" OnClick="BtnClear_Click" />
</td>
</tr>
</table>
</center>
</fieldset>
<br />
<br />
<br />
<fieldset style="border-bottom-style: solid; border-left-style: solid; border-right-style: solid; border-top-style: solid; border-top-width: 3px; border-color: #0071ad;">
<legend style="background-color: #0071ad; border-radius: 10px; font-size: 14px; padding: 7px; color: white; font-family: open_sans_condensedbold,arail;">
<asp:Label ID="lblmemsearch" runat="server" Font-Bold="true" Text="Enter Flag Code"></asp:Label> 
<asp:TextBox ID="txtsearch" placeholder="Enter Flag Code" runat="server" AutoPostBack="true"></asp:TextBox>
<asp:Button ID="BtnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" />
</legend>
<br />
<table style="float: right;">
<tr>
<td class="tdtext">No of Records:</td>
<td>
<asp:Label ID="lblRecordsCount" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
<br />
<div style="width: 98%; height: auto;">
<asp:GridView ID="grdGSMMasterDetails" runat="server" AutoGenerateColumns="False" AllowSorting="true" ShowFooter="True"
Width="1400px" Height="12" ShowHeader="True" CellPadding="4" ForeColor="#333333" GridLines="Both" OnRowDataBound="grdGSMMasterDetails_RowDataBound" OnSorting="grdGSMMasterDetails_Sorting">
<PagerStyle BackColor="#7779AF" Font-Bold="true" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<Columns>....</columns
<FooterStyle BackColor="#016091" ForeColor="#FFFFCC" Font-Bold="True" />
<PagerStyle BackColor="#ffccff" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#016091" Font-Bold="True" ForeColor="white" HorizontalAlign="Left" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</fieldset>
</div>
</ContentTemplate>
</asp:UpdatePanel>