Unable to retrieve contents on RowEditing (to cancel editing)

R

Radu

Hi. I have struggled for two hours now with this:

<asp:GridView
ID="GridView1"
DataSourceID="SqlDataSource1"
DataKeyNames="ID"
AutoGenerateColumns="False"
ShowFooter="True"
OnRowUpdating="GridView1_RowUpdating"
OnRowEditing="GridView1_RowEditing"
OnRowDataBound="GridView1_RowDataBound"
Runat="server"<asp:TemplateField
HeaderText="Action Type">
<ItemTemplate>
<asp:Label ID="ActionTakenLabel" Runat="Server" ><%#
Eval("ActionTaken")%></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList
ID="ActionTakenComboBoxAdd"
AutoPostBack="false"
DataSourceID="SqlDataSource2"
DataTextField="ActionTaken"
DataValueField="ActionTaken"
Runat="server">
</asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ActionTakenComboBoxEdit"
AutoPostBack="false" DataSourceID="SqlDataSource2"
DataTextField="ActionTaken"
DataValueField="ActionTaken"
Runat="server" Text='<%# Eval("ActionTaken")%>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>



protected void GridView1_RowEditing(object sender,
System.Web.UI.WebControls.GridViewEditEventArgs e)
{
String ActionType = ((DropDownList)
(GridView1.Rows[e.NewEditIndex].FindControl("ActionTakenComboBoxEdit"))).SelectedValue;

if (ActionType.IndexOf("Manually") >= 0)
{
// Cancel the edit operation.
e.Cancel = true;
String strMessage;
strMessage = "You cannot edit this record.";
Response.Write("<script language='javascript'>alert('" + strMessage
+ "');</script>");
}
}
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top