473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Datagrid ItemCommand problems

(originally posted on framework.aspnet.datagridcontrol)

Hi, I don't seem to be able to get a imagebutton (within a template column)
to fire an itemcommand event when clicked. Looking through this NG, it seems
like the same problem has been raised many times, except in most cases the
problem occurs as the datagrid's databind method is being called on
Postback - something that definately isn't happening in my code.

I also have a standard ButtonColumn labled 'test' - which when clicked seems
to work fine, i.e the dgFileList_ItemCommand fucntion is executed.

Can anybody tell me why the event isn't being raised by a click of the
imagebutton (it's definately doing a postback, but thats all)? Is it
anything to do with the fact its a user control?

Any help is greatly appreciated

Here are the relevant sections of my code:
..ascx
<asp:datagrid id="dgFileList" Enabled="False" AutoGenerateColumns="False"
runat="server">
<Columns>
<asp:ButtonColumn Text="test"></asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:ImageButton CommandName="ClickMe" ImageUrl='<%#
DataBinder.Eval(Container.DataItem, "ThumbURL")%>' id="ImageSelectButton"
runat="server">
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
..ascx.cs
public abstract class FlieList : System.Web.UI.UserControl

{

protected System.Web.UI.WebControls.DataGrid dgFileList;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//this.ShowFiles();

}

public void ShowFiles()

{

//Datagrid - Get file list

Files files = new Files();

FileItem[] fileList = files.GetFileList();

dgFileList.DataSource = fileList;

dgFileList.DataBind();

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.dgFileList.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgFileList_ItemCo
mmand);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void dgFileList_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

string s = "test";

string y = "anothertest";

if(e.CommandName=="ClickMe")

{

s = "test";

y = "anothertest";

}

s += y;

}



Nov 18 '05 #1
0 1130

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
0
by: Solomon Shaffer | last post by:
I am trying to add some link buttons to a datagrid template column at runtime and trying to wire these buttons up to the ItemCommand event (or any event when clicked!). The ItemCommand event works...
0
by: Colin Ramsay | last post by:
Hi all, I don't normally post swathes of code like this but I am truly banging my head off my desk here... I've dynamically created a datagrid within a usercontrol. There are two columns...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
2
by: Syed Sami R. Shah | last post by:
hi all, i am having problem with using itemcommand of datagrid by way of asp:image button. i have put an image button in a datagrid item template and have set CommandName="DeleteRecord" and have...
2
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
1
by: kevin | last post by:
Hi, I'm working with VS 2005 and Framework 2.0 I have a datagrid with a link and the selectedindexchanged will not fire. The page posts back but does nothing. Protected Sub...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.