Hello,
I need your help.
On my Gridvew in C# ASP.NET I have
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="btnedit" runat="server" CommandName="Edit"
ImageUrl="edit_icon.gif" ToolTip= "Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="btncancel" runat="server" CommandName="Cancel"
ImageUrl="cancel.gif" ToolTip="Cancel editing" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BS"
ItemStyle-HorizontalAlign="Justify">
<ItemTemplate>
<asp:Label ID="lbBS" runat="server" CssClass="ddl_Class_new"
Text='<%# HttpUtility.HtmlDecode(MaP.SpliceText(Eval("BS").ToString(),11)) %>'>
</asp:Label>
</ItemTemplate>
<asp:TemplateField HeaderText="F" ItemStyle-CssClass="ddl_Class_new"
ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblF" runat="server" Text='<%# Eval("F") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl" runat="server" CssClass="ddl_Class_new"
AutoPostBack="true" BackColor="Yellow" OnSelectedIndexChanged="ddl">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
I have problem when I try to cancel editing in the row, because if I have selected one value in DropDownList "ddl", e.g. "A" value instead of cancel editing it's opened the page "Default.aspx" and not cancel edit in GridView.
but if I delete AutoPostBack true, the Redirect don't working.
I have tried using without success
protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gv.EditIndex = -1;
DropDownList ddl = (DropDownList)FindControl("ddl");
ddl.Items.Clear();
DataBind;
}
protected void ddl(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;
string value = (string)list.SelectedValue;
switch (value)
{
case "A":
Server.Transfer("Default.aspx");
break;
case "B":
Server.Transfer("Default2.aspx");
break;
}
}
Can you help me?