我是相當新的ASP/C#和我工作的一個項目,運行時SQL存儲過程會產生基於數據的報告,我現在使用'前5個sql記錄'填充數據列表。ASP C#Datalist中OnItemDataBound事件要更改其他單元格內容
我在訪問數據列表數據的問題,我想根據拉字段的值更改拉到現場的對準單元。
我有一個DataList設置與OnItemBound程序。
頁代碼:
<asp:DataList ID="DataList2" runat="server" onitemdatabound="DataList2_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>Certification Date</th>
<th colspan="2">As Found Potential</th>
<th>As Found Tolerance</th>
<th colspan="2">As Left Potential</th>
<th>As Left Tolerance</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="td04">
<asp:Label ID="certificationDate" runat="server" Text='<%# Eval("as_left_date", "{0:MM/dd/yyy}") %>' /> <!-- Certification Date Always As Left -->
</td>
<td class="td05">
<asp:Label ID="asFoundPotential" runat="server" Text='<%# Convert.ToDouble(Eval("as_found_entered")) %>' /> <!-- As Found Entered -->
</td>
<td class="td06">
<div>mV</div>
</td>
<td class="td04">
<asp:Label ID="asFoundTolerance" runat="server" Text='In Tolerance' /> <!-- ItemDataBound to Change Contents -->
</td>
<td class="td05">
<asp:Label ID="asLeftPotential" runat="server" Text='<%# Eval("as_left_entered") %>' /> <!-- As Left Entered -->
</td>
<td class="td06">
<div>mV</div>
</td>
<td class="td04">
<asp:Label ID="asLeftTolerance" runat="server" Text='In Tolerance' /> <!-- ItemDataBound to Change Contents -->
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
代碼背後:
protected void dataTable2()
{
string constr = ConfigurationManager.ConnectionStrings["Records"].ConnectionString;
SqlConnection conn = new SqlConnection(constr);
SqlCommand myCommand = new SqlCommand("report_page", conn);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@serial_number", serial_number.Text);
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(myCommand);
try
{
conn.Open();
adp.Fill(ds);
DataList2.DataSource = ds.Tables[0];
DataList2.DataBind();
}
catch (SqlException ex)
{
writeToFile(Environment.NewLine + "SQL DataTable2 Error: " + ex.Message);
}
finally
{
conn.Close();
myCommand.Dispose();
}
}
OnDataBound事件:
protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
//cell change code goes here
}
的 「寬容」 細胞/字符串內容我想改變基於這是雙倍的「as_found_entered」值。任何援助表示讚賞。
感謝你爲這個。有了這個snipet,我終於開始工作了! – SDG