Hi Sam,
I will help you another button height and event handle question in this
reply.
To manipulate the child controls in datagrid, normally, you have 2 ways:
declare and dynamic refer it.
To declare refer it, you should leverage TemplateColumn and declare its
height in the <asp:Button> tag. Also, you may add the button's click event
handler through declare. Like this:
<asp:datagrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button ID="bt" Height="40px" OnClick="ClickEventHandler"
Runat="server" Text="Button"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Then, you should write a method named "ClickEventHandler" to handle the
Click event.(Note: if you writen ClickEventHandler in code behind, you
should mark it as "protected" or "public", you should not specify it as
"private", or a run-time error will generate)
Also, you may not use TemplateColumn, just use a ButtonColumn. Then you can
not use declare way to manipulate it. You have to manipulate it dynamically
at run-time in DataGrid.ItemCreated event. Like this:
private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem dgi=e.Item;
if(dgi.ItemType ==ListItemType.Item ||dgi.ItemType
==ListItemType.AlternatingItem)
{
//I suppose your ButtonColumn is the first
column in DataGrid
foreach(Control c in dgi.Cells[0].Controls)
{
if(c is Button)
{
Button bt=(Button)c;
bt.Height=Unit.Pixel(40);
bt.Click +=new EventHandler(bt_Click);
}
}
}
}
private void bt_Click(object sender, EventArgs e)
{
}
Also, because DataGrid has exposed an event of DataGrid.ItemCommand, which
occurs when any button is clicked in the DataGrid control. So to handle the
Button click in the DataGrid, you can just handler DataGrid.ItemCommand
event. In this event, in order to determine which row's button is clicked,
you can just use DataGridCommandEventArgs.Item.ItemIndex
Like this:
private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.Response.Write("ItemCommand +"+ e.Item.ItemIndex.ToString());
}
================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.