如何在我的web應用程序中清除我的表格數據時,只要我選擇了我已插入到我的下拉列表中的默認值?如何在選擇下拉列表的默認值時清除表格數據
我有3個選項
- SelectPoliceReportID(默認值)
- PoliceReportID123(數據庫值)
- PoliceReportID456(數據庫值)
當我選擇一個數據庫中的下拉列表框值時,它們將顯示單個DB值,但是當我選擇默認值時,先前單擊的DB值信息仍將保留在表數據上。
這是我的頁面加載代碼,其中policereportID將顯示
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
SqlCommand cm = new SqlCommand("Select pr.policereportid from PoliceReport pr, MemberReport mr where pr.memberreportid=mr.memberreportid and mr.caseprogress='completed'", con);
con.Open();
SqlDataReader dr;
dr = cm.ExecuteReader();
while (dr.Read())
{
DDLCase.Items.Add(dr["policereportid"].ToString());
}
dr.Close();
con.Close();
}
在我剛纔的問題,我只能通過我的數據綁定後插入下面的代碼從我的GridView清除我的數據
DDLCase.Items.Clear();
DDLCase.DataSource = ds2;
DDLCase.DataTextField = "memberreportid";
DDLCase.DataValueField = "memberreportid";
DDLCase.DataBind();
DDLCase.Items.Insert(0, new ListItem("Select Member Report ID", ""));
DDLCase.SelectedIndex = 0;
這裏是我的下拉列表我的表
protected void DDLCase_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
con.Open();
SqlCommand cm = new SqlCommand("Select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, pr.policeid, pr.prdatetime, pr.policereport, pr.image1, mr.citizenreport from MemberReport mr, PoliceReport pr, LoginRegisterOthers lro where pr.policereportid = '" + DDLCase.SelectedValue + "' and mr.memberreportid=pr.memberreportid and lro.username=mr.username and mr.caseprogress='completed'", con);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
lblFullName.Text = dr["fullname"].ToString();
lblContact.Text = dr["contact"].ToString();
lblTOC.Text = dr["typeofcrime"].ToString();
lblLocation.Text = dr["location"].ToString();
lblCRDT.Text = dr["crdatetime"].ToString();
lblPicture.Text = dr["image1"].ToString();
lblAssign.Text = dr["policeid"].ToString();
lblPRDT.Text = dr["prdatetime"].ToString();
lblCR.Text = dr["citizenreport"].ToString();
lblPR.Text = dr["policereport"].ToString();
}
con.Close();
}
的源代碼。我沒有使用asp:表。我以編程方式將該表添加到源代碼中。
<table style="width: 100%; height: 576px;">
<tr>
<th style="width: 595px; height: 49px;">Full Name :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblFullName" runat="server" Text=""></asp:Label>
</td>
<th style="height: 49px; width: 134px">Contact :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblContact" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">Location :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblLocation" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Type of Crime :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblTOC" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">Picture : </th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblPicture" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Citizen Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblCRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">AssignTo :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblAssign" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Police Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblPRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 100px;">Citizen Report :</th>
<td colspan="4" style="height: 100px" text-align:"left">
<asp:Label ID="lblCR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 135px;">Police Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblPR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px">
<asp:TextBox ID="tbofficial" runat="server" Height="121px" TextMode="MultiLine" Width="878px" ></asp:TextBox>
<br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnClear_Click" />
</td>
</tr>
</table>
這裏設置
yourtable.visible =false;
'表data'是C#'datatable'或數據庫'datatable' – Rahul如果它是一個C#'DataTable'然後使用'table.Clear();' – Rahul