我要启用或根据条件对GridView控件的某些行禁用LinkButton的链接按钮..我可以一行启用的LinkButton和禁用它放在同一网格视图的另一行??我的代码是在这里启用和禁用的GridView
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{LinkButton lnk2 = (LinkButton)e.Row.FindControl("LinkButton2");
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlCommand cmd12 = new SqlCommand("Select testsession_status from student_vs_testsession_details where testsession_id='" + v_testid.Text + "' ", con12);
SqlDataReader dr12 = cmd12.ExecuteReader();
while (dr12.Read())
{
string test_status = dr12[0].ToString();
LinkButton lnk2 = (LinkButton)e.Row.FindControl("LinkButton2");
foreach (GridViewRow row in GridView1.Rows)
{
if (v_testtype == "Theory Test" && test_status == "Completed")
{
lnk2.Visible = true;
}
else
{
lnk2.Visible = false;
}
}
}
实际上你的问题是什么,这段代码不起作用,你有什么错误信息吗?对我来说,貌似没有工作,但不必在我的调试器,幽冥知道你的计划,你的逻辑流程我不建议你做什么。 - 一个错误是,你不觉得在每行LinkButton的,第二个错误是,你不与数据库中的每个线路连接在GridView的每一行。 – Aristos
在这种情况下,您可以通过GridView控件需要循环,并设置链接按钮启用/禁用相应的,因为上面的代码将仅看当前行项目。而不是整行。 的foreach(的DataGridViewRow行中grid.Rows) { 变种链路= row.FindControl( “LinkButton2”) } –
i循环通过每个行和如何可以检查启用/禁用的LinkButton条件?作为@Deepu说代码看起来只有当前排ITM .. – ARATHY