asp.Netデータバインド時にデータ列をカスタマイズする

1359 ワード

 
  
protected void dgQuery_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
{
DataRow drRow = ((DataRowView)e.Item.DataItem).Row;
string commonPartId = drRow["cniBackup1"].ToString();
HyperLink hlTrans = (HyperLink)e.Item.FindControl("hlTrans");
if (hlTrans != null)
{
hlTrans.Text = "--";
hlTrans.NavigateUrl = "javascript:void();";
}

//
LinkButton btnDelete = (LinkButton)e.Item.FindControl("btnDelete");
//
if (!bCanDelete && btnDelete != null)
{
// Cell
for (int i = 0; i < e.Item.Cells.Count; i++)
{
if (e.Item.Cells[i].HasControls() && e.Item.Cells[i].Controls.IndexOf(btnDelete) > 0)
{
int index = e.Item.Cells[i].Controls.IndexOf(btnDelete);
e.Item.Cells[i].Controls.RemoveAt(index);
Literal tips = new Literal();
tips.Text = "--";
e.Item.Cells[i].Controls.AddAt(index, tips);

//e.Item.Cells[i].Text = "--";
break;
}
}
}
}
}