Javascript ASP C#Datalist OnItemDataBound事件以更改另一个单元格内容
我对asp/c相当陌生,我正在从事一个项目,当运行一个sql存储过程时,它将根据数据生成一个报告,我现在正在用“前5条sql记录”填充一个datalist表 我遇到了访问datalist数据的问题,我想根据拉入字段的值更改拉入字段的对齐单元格 我有一个带有OnItemBound程序的数据列表设置 页面代码:Javascript ASP C#Datalist OnItemDataBound事件以更改另一个单元格内容,javascript,c#,asp.net,datalist,Javascript,C#,Asp.net,Datalist,我对asp/c相当陌生,我正在从事一个项目,当运行一个sql存储过程时,它将根据数据生成一个报告,我现在正在用“前5条sql记录”填充一个datalist表 我遇到了访问datalist数据的问题,我想根据拉入字段的值更改拉入字段的对齐单元格 我有一个带有OnItemBound程序的数据列表设置 页面代码: 认证日期 已发现的潜力 发现公差 As左势 作为左公差 mV mV 代码隐藏: 受保护的无效数据表2() { string constr=ConfigurationManager.Con
认证日期
已发现的潜力
发现公差
As左势
作为左公差
mV
mV
代码隐藏:
受保护的无效数据表2()
{
string constr=ConfigurationManager.ConnectionString[“记录”].ConnectionString;
SqlConnection conn=新的SqlConnection(cont);
SqlCommand myCommand=新的SqlCommand(“报告页面”,conn);
myCommand.CommandType=CommandType.StoredProcess;
myCommand.Parameters.AddWithValue(“@serial\u number”,serial\u number.Text);
数据集ds=新数据集();
SqlDataAdapter adp=新的SqlDataAdapter(myCommand);
尝试
{
conn.Open();
自动进料(ds);
DataList2.DataSource=ds.Tables[0];
DataList2.DataBind();
}
catch(SqlException-ex)
{
writeToFile(Environment.NewLine+“SQL DataTable2错误:”+ex.Message);
}
最后
{
康涅狄格州关闭();
myCommand.Dispose();
}
}
OnDataBound事件:
protectedvoid DataList2\u ItemDataBound(对象发送方,DataListItemEventArgs e)
{
//换手机代码在这里
}
我想根据双精度的“as_found_entered”值更改“In Tolerance”单元格/字符串内容。感谢您的帮助
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// Retrieve the Label control in the current DataListItem.
Label asFoundPotential = (Label)e.Item.FindControl("asFoundPotential");
// You can convert the asFoundPotential lable value in double.
if (asFoundPotential = Something)
{
// identify the specific cell of asLeftPotential and assign whatever you want to change
}
}
希望此伪代码能帮助您将需要的内容放入Itemdatabound事件中。这就是最终成功的地方。标签引用是关键,要加倍的标签有点混乱
protectedvoid DataList2\u ItemDataBound(对象发送方,DataListItemEventArgs e)
{
如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem)
{
标签asFoundTolerance=(标签)e.Item.FindControl(“asFoundTolerance”);
标签asLeftTolerance=(标签)e.Item.FindControl(“asLeftTolerance”);
标签asFoundPotential=(标签)e.Item.FindControl(“asFoundPotential”);
double foundPot=Convert.ToDouble(asFoundPotential.Text);
如果(foundPot<305.5 | | foundPot>326.4)
{
asFoundTolerance.Text=“超出公差”;
be4TestG.Checked=false;
be4TestB.Checked=true;
}
其他的
{
asFoundTolerance.Text=“In Tolerance”;
be4TestG.Checked=真;
be4TestB.Checked=false;
}
Label asLeftPotential=(Label)e.Item.FindControl(“asLeftPotential”);
double leftPot=Convert.ToDouble(asLeftPotential.Text);
如果(leftPot<305.5 | | leftPot>326.4)
{
asLeftTolerance.Text=“超出公差”;
aftTestG.Checked=false;
aftTestB.Checked=true;
}
其他的
{
asLeftTolerance.Text=“在公差中”;
aftTestG.Checked=true;
aftTestB.Checked=false;
}
}
}
谢谢您的帮助。有了这个狙击手,我终于成功了!