0
我已经在OnRowCreated方法中的标题行上使用SetRenderMethodDelegate在我的GridView中绘制了自定义标题图。尽管我试图将LinkButton添加到新的标题行,但我遇到了问题。GridView中的自定义标题
这是RenderMethod的样子:
private void RenderSelectionMode(HtmlTextWriter output, Control container)
{
TableHeaderCell cell = new TableHeaderCell();
cell.Attributes["colspan"] = container.Controls.Count.ToString();
AddSelectionModeContents(cell);
cell.RenderControl(output);
output.WriteEndTag("tr");
HeaderStyle.AddAttributesToRender(output);
output.WriteBeginTag("tr");
for(int i = 0; i < container.Controls.Count; i++)
{
DataControlFieldHeaderCell cell = (DataControlFieldHeaderCell)container.Controls[i];
cell.RenderControl(output);
}
}
private void AddSelectionModeContents(Control parent)
{
// TODO: should add css classes
HtmlGenericControl label = new HtmlGenericControl("label");
label.InnerText = "Select:";
selectNoneLK = new LinkButton();
selectNoneLK.ID = "SelectNoneLK";
selectNoneLK.Text = "None";
//selectNoneLK.Attributes["href"] = Page.ClientScript.GetPostBackClientHyperlink(selectNoneLK, "");
//selectNoneLK.Click += SelectNoneLK_Click;
selectNoneLK.Command += SelectNoneLK_Click;
selectAllLK = new LinkButton();
selectAllLK.ID = "SelectAllLK";
selectAllLK.Text = "All";
//selectAllLK.Attributes["href"] = Page.ClientScript.GetPostBackClientHyperlink(selectAllLK, "");
//selectAllLK.Click += SelectAllLK_Click;
selectAllLK.Command += SelectAllLK_Click;
parent.Controls.Add(label);
parent.Controls.Add(selectNoneLK);
parent.Controls.Add(selectAllLK);
}
正如你所看到的,我已经尝试了不同的方式让我的工作了LinkButton(有没有工作,虽然)。该了LinkButton呈现为普通锚标签,就像这样:<一个ID =“SelectNoneLK” >无</A >
我知道有一些错误的事实,ID看起来像这样,因为我使用的是这个主页和ID应该是更长的东西。
任何帮助,将不胜感激!
尼克
我改为通过OnDataBound中的层次结构添加它们,但不幸的是,如果发生回发而没有绑定数据,则该行会消失。此外,尽管它们现在可点击并且ID似乎是正确的,但似乎没有引发事件。 – 2009-02-05 19:11:43