bmutch
asked on
Click on text in a dotnet asp datagrid cell and run server event.
Currently I have a company org. chart displayed in an asp.net datagrid, and a button in the first cell. If user clicks button all the employees (rows) beneath (and under authority of) that person are displayed to show the command chain, click button again and the branch is collapsed. I want to accomplish the same thing by clicking on the employees name ( the column position that displays the employees name is dynamic of couse depending on where the employee is in the command chain). It would just be nice if the user did not have to locate the correct button (row) in the first column that is associated with the name they are looking at, so I want them to be able to click the name instead. How can I best accomplish this. (VS 2008)
thanks.
thanks.
Hi,
have you thought about using a ButtonField rather than BoundField here?
Regards
have you thought about using a ButtonField rather than BoundField here?
Regards
ASKER
sgomzin: I've used the hyperlink before to open a new browser window, but do you have any details (code) as to how I could click on it and have it behave like a grid button would, ie cause a postback and run the itemcommand method?
Allister_Reid: thought about using buttonfield but would prefer the text.
Allister_Reid: thought about using buttonfield but would prefer the text.
<asp:ButtonField ButtonType="Link" ... >
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfieldbase.buttontype.aspx
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfieldbase.buttontype.aspx
Hi Allister_Reid,
I guess that's what you are looking for: use TemplateField with LinkButton. Set Text to the employee name, and commandArgument - to the employee ID, and create OnClick event. So when user clicks on the employee name you will receive the employee ID in in the event argument in server side event handler.
I guess that's what you are looking for: use TemplateField with LinkButton. Set Text to the employee name, and commandArgument - to the employee ID, and create OnClick event. So when user clicks on the employee name you will receive the employee ID in in the event argument in server side event handler.
<asp:TemplateField HeaderText="TemplateField">
<ItemTemplate>
<asp:LinkButton runat="server" ID="DetailsLinkButton"
Text='<%# Eval("EMPLOYEE_NAME") %>' CommandName="DetailsLinkButton"
CommandArgument='<%# Eval("EMPLOYEE_ID") %>' OnClick="DetailsLinkButton_Click" />
</ItemTemplate>
</asp:TemplateField>
public void DetailsLinkButton_Click(Object sender, EventArgs e)
{
if (sender is LinkButton)
{
int EMPLOYEEID = Convert.ToInt32((sender as LinkButton).CommandArgument);
}
}
Sorry bmutch, the last comment was addressed to you
I'm not sure there's a need to go for a template field here, have you tried a ButtonField and changing the type to Link?
ASKER
The buttoncolumn is working well. But I do have a question on it. I would like to only have the buttons "clickable" if they actually have people working for them. Is there a way to somehow "disable" the link on the buttoncolumn?
thanks.
thanks.
Yeah, you can set the Enabled property of the button to false. You may be able to do this when you are populating the text?
ASKER
ok, cool. Is there anyway to avoid the "grayed-out" look of the disabled button though, I tried this but It didn't work:
btn.ForeColor = Color.Green
thanks.
btn.ForeColor = Color.Green
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very good, thanks.
ASKER
excellent
You should use HyperLinkField. Display employee name using DataTextField. Create dynamic link using DataNavigateUrlFormatStrin
Example:
<asp:HyperLinkField DataNavigateUrlFields="EMP
DataNavigateUrlFormatStrin
DataTextField="EMPLOYEE_NA