Forum Moderators: open
The application is a phone menu. Users search a name, and it returns matching links in a datagrid. The last column of each row is a Magnifying Glass image (asp:ImageButton). When the user clicks the magnifying glass I need it to run a method in the code behind.
My problem is this: Each row has an ID associated to it that uniquely identifies the user. I need the OnClick for each Image to pass this # into the method. However, in order to get the method to work, I had to create the method like the following:
public void detailsClick(object sender, System.Web.UI.ImageClickEventArgs e)
{
//code here
}
If I try to add a third item to the method like this it fails:
public void detailsClick(object sender, System.Web.UI.ImageClickEventArgs e, int ID)
{
//code here
}
In testing the functionality, I was able to accomplish the passing of the ID by using a regular link and this code within the datagrid on the aspx page:
<asp:TemplateColumn HeaderText="Details">
<ItemTemplate>
<div align='center'>
<a href="Details.aspx?id=<%# DataBinder.Eval(Container.DataItem, "EMPLOYEE_ID")%>"><img border="0" src="images/magnify.gif"></a>
</div>
</ItemTemplate>
</asp:TemplateColumn>
However I can't seem to figure out a way to pass the EMPLOYEE_ID item to a method in code behind.
I'm sure that this issue has a lot to do with my lack of knowledge of how (object sender, eventargs e) works and why it is necessary...but I'm hoping that someone can help me to understand what it is that I need to do to solve my problem.
Thank you
-Mike
[odetocode.com...]
Scroll down to FindControl in DataGrid, and that should point you in the right direction.
private void DataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if(e.CommandName=="Search")
{
//do somthing
string variable=e.CommandArguement;
}}
<asp:Button id=button runat="server" Text="somthing" CommandName="search" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"SomeVariable") %>'>
<asp:datagrid id = "MyGrid" datakeyfield = "YourDatabaseIDColumn">
You can then reference it by "MyGrid.DataKeys". I suggest doing some more research on this, as I have not provided enough information (only because I don't have a real firm knowledge of it myself).
Red_Eye, after a little hacking around I got your solution to work! I will post some pseudo code when I get a minute to put it together for the future integrity of this post as a reference.
mattglet, I got your reply post-Solution...however I will make an attempt to try that out when I get [another] minute, becuase it seems like a simple concept that could come in handy down the road.
macrost...that link was a little overwhelming and I had some trouble finding anything I could use ..but I do appreciate the help anyway
thanks :)
-Mike