Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid.SelectedIndex=-1 1

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
0
0
US
How can I capture SelectedIndex of the datagrid when user clicks html image("media/i_edit.gif") that is contained in datagrid? In my datagrid I have:
<asp:TemplateField ItemStyle-CssClass="edit" HeaderStyle-CssClass="edit">
<HeaderTemplate><img src="media/i_add.gif" alt="add" onclick="rowAdd()" /></HeaderTemplate>
<ItemTemplate>
<img alt="view/edit properties" runat="server" id ="Edit" class="edit" src="media/i_edit.gif" />
</ItemTemplate>
</asp:TemplateField>

So I need SelectedIndex for the datagrid to update when they click i_Edit image

thanks
 
I think this will work in a TemplateField
Code:
<asp:DataGrid id=DataGrid1 runat=server [b]OnEditCommand="yourEditRoutine"[/b]
<ItemTemplate>
                <img alt="view/edit properties"  runat="server" id ="Edit"  class="edit" src="media/i_edit.gif" [b]CommandName="Edit"[/b]   />
            </ItemTemplate>
...
...

void yourEditRoutine(object sender, DataGridCommandEventArgs e)
{
    DataGrid1.EditItemIndex = e.Item.ItemIndex;
    //continue on as normal
}
 
oops

<asp:ImageButton id="imgEdit" runat="server" ImageUrl="media/i_edit.gif" ToolTip="View/Edit Properties" CommandName="yourEditRoutine" />
 
ARGH... sorry

CommandName="yourEditRoutine"

needs to be

CommandName="Edit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top