Firing a DataGrid's Edit event when a row is clicked

M

Mark Rae

Guys,

Apologies for asking this, but it's late and I'm clearly missing something
fairly obvious...

I have an <asp:DataGrid > control defined thus:

<asp:DataGrid ID=dgrdResults Runat=server
OnEditCommand="dgrdResults_Edit"
OnPageIndexChanged="dgrdResults_PageIndexChanged"
OnSortCommand="dgrdResults_Sort" OnItemDataBound="dgrdResults_ItemDataBound"
AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true"
PageSize="10" PagerStyle-NextPageText="Next >" PagerStyle-PrevPageText="<
Previous" PagerStyle-HorizontalAlign="Left" PagerStyle-Mode="NumericPages"
HorizontalAlign="Left" DataKeyField="intBusinessIDcnt"
PagerStyle-Font-Size="8" CellPadding="3" BorderWidth="1px"
BorderStyle="Solid">
<HeaderStyle Font-Bold="True" BackColor="#e5e5e5" Font-Name="Verdana"
ForeColor=Black Font-Size="XX-Small" Font-Underline="false"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="intBusinessIDcnt" Visible=False />
<asp:ButtonColumn CommandName="Edit" DataTextField="strBusiness"
HeaderText="Name" SortExpression="strBusiness" ItemStyle-Wrap="False"
HeaderStyle-Wrap="false" />
<asp:BoundColumn DataField="intProjects" HeaderText="Projects"
SortExpression="intProjects" ItemStyle-Wrap="False" HeaderStyle-Wrap="false"
ItemStyle-HorizontalAlign="Right"/>
</Columns>
<ItemStyle Font-Name="Verdana" Font-Size="XX-Small" />
<AlternatingItemStyle BackColor="WhiteSmoke" />
<FooterStyle ForeColor="Black" BackColor="#CCCC99" Font-Size="XX-Small"
Font-Name="Verdana"></FooterStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="Black"
BackColor="White"></PagerStyle>
</asp:DataGrid>

I'm trying to make its OnEditCommand event fire when a row is clicked. I
know I've done this before, but I can't get it to work tonight...

The dgrdResults_ItemDataBound() method is as follows:

public void dgrdResults_ItemDataBound(object sender, DataGridItemEventArgs
e)
{
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='white'");
}
if(e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='WhiteSmoke'");
}
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='LemonChiffon'");
e.Item.Style["cursor"] = "hand";
e.Item.Attributes["onclick"] =
Page.GetPostBackEventReference(Page.FindControl("dgrdResults"),
"OnEditCommand");
}
}

When I click a row, the page posts back, but doesn't fire the
dgrdResults_Edit event...

Help!

Any assistance gratefully received.

Mark
 
M

Mark Rae

Apologies for asking this, but it's late and I'm clearly missing something
fairly obvious...

As anticipated, I looked at this again first thing this morning, went
"D'oh!", and fixed it straightaway.

Sorry for the wasted bandwidth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top