Confirmation during a datagrid column deletion. (e

Lady nina

New Member
Hey guys...<BR><BR>I need some help with Datagrid. <BR>My question is on setting a confirmation during a datagrid column deletion.<BR>Everything works great, not until I added a code that triggers the delete confirmation bmessage box.<BR>I am using Visual Studio.net as my tool.<BR>I found a good article on this site and I tailored my vode based upon that reference.<BR>(http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=228&page=2).<BR>In fact I notice that this error(error CS0117) occurs whenever I add a new declaration on the Datagrid, <BR>in this case, when I added [OnItemDataBound="myDataGrid_OnItemDataBound"]<BR><BR>ANY HELP ON THIS IS GREATLY APPRECIATED...<BR><BR>Below are the details of my problem.<BR><BR><BR>Error message:<BR><BR>[Compiler Error Message: CS0117: 'ASP.school_name_aspx' does not contain a definition for 'myDataGrid_OnItemDataBound']<BR><BR><BR>The problem occurs in this specific area at my Datagrid declaration (OnItemDataBound="myDataGrid_OnItemDataBound")<BR>----------------------------------------------------------------------------------------------<BR><asp:datagrid id="DataGrid2" runat="server" DataKeyField="ID" CellPadding="3" BackColor="White"<BR>BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC"<BR>AutoGenerateColumns="False" OnItemDataBound="myDataGrid_OnItemDataBound"><BR>.<BR>.<BR>.<BR>.<BR>.<BR>.<BR>.<BR>.<BR>.<BR>this is the link button(contain in the Datagrid above) that I want to set up a confirmation message box....<BR><asp:linkbutton id="DeleteLink" runat="server" text="Delete" commandname="Delete" /><BR>---------------------------------------------------------------------------<BR><BR><BR>I added this function on the behind-code <BR>----------------------------------------<BR>private void myDataGrid_OnItemDataBound(object sender, DataGridItemEventArgs e)<BR>{<BR>if(e.Item.FindControl("DeleteLink") != null)<BR> { <BR> ((LinkButton) e.Item.FindControl("DeleteLink")).Attributes.Add("onClick", "return confirm('Are you sure you wish to delete this item?');");<BR> }<BR>} <BR><BR><BR>Datagrid code on school-name.aspx <BR>---------------------------------<BR>asp:datagrid id="DataGrid2" runat="server" DataKeyField="ID" CellPadding="3" BackColor="White"<BR>BorderWidth="1px" BorderStyle="None" BorderColor="#CCCCCC"<BR>AutoGenerateColumns="False" OnItemDataBound="myDataGrid_OnItemDataBound"><BR><!-- **** ABOVE IS WHERE I ADDED THIS CODE (OnItemDataBound="myDataGrid_OnItemDataBound") ************ --><BR><BR><SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle><BR><ItemStyle ForeColor="#000066"></ItemStyle><BR><HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle><BR><FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle><BR><Columns><BR><asp:TemplateColumn><BR><ItemTemplate><BR><BR><!--***** THIS IS MY DELETE LINK BUTTON ************************************************** *** --><BR><asp:linkbutton id="DeleteLink" runat="server" text="Delete" commandname="Delete" /> <BR></ItemTemplate><BR></asp:TemplateColumn><BR><asp:BoundColumn DataField="ID" ReadOnly="True" HeaderText="ID"></asp:BoundColumn><BR><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn><BR><asp:TemplateColumn HeaderText="Name"><BR><ItemTemplate><BR><%#DataBinder.Eval(Container.DataItem, "name" )%><BR></ItemTemplate><BR><EditItemTemplate><BR><asp:TextBox ID="txtName" Text='<%#DataBinder.Eval(Container.DataItem, "name" )%>' Size="40" runat="server" MaxLength="100"/><BR><asp:RequiredFieldValidator ControlToValidate="txtName" Text="*" Runat="server" ErrorMessage="'School Name' field is required!" /><BR></EditItemTemplate><BR></asp:TemplateColumn><BR><asp:TemplateColumn HeaderText="Year Start"><BR><ItemTemplate><BR><%#DataBinder.Eval(Container.DataItem, "year_start" )%><BR></ItemTemplate><BR><EditItemTemplate><BR><asp:TextBox ID="txtYearStart" Text='<%#DataBinder.Eval(Container.DataItem, "year_start" )%>' Size="4" runat="server" MaxLength="4" /><BR><asp:RequiredFieldValidator ControlToValidate="txtYearStart" Text="*" Runat="server" ID="Requiredfieldvalidator1"<BR>ErrorMessage="'Year Start' field is required! " /><BR><asp:RangeValidator id="Rangevalidator2" runat="server" ErrorMessage="'Year Start' should be an integer with yyyy format! The minimum value is 1800"<BR>ControlToValidate="txtYearStart" Type="Integer" MaximumValue=http://aspmessageboard.com/archive/index.php/"9999" MinimumValue="1800">yyyy</asp:RangeValidator><BR></EditItemTemplate><BR></asp:TemplateColumn><BR><asp:TemplateColumn HeaderText="Year End"><BR><ItemTemplate><BR><%#DataBinder.Eval(Container.DataItem, "year_end" )%><BR></ItemTemplate><BR><EditItemTemplate><BR><asp:TextBox ID="txtYearEnd" Text='<%#DataBinder.Eval(Container.DataItem, "year_end" )%>' Size="7" runat="server" MaxLength="7" /><BR><asp:RequiredFieldValidator ControlToValidate="txtYearEnd" Text="*" Runat="server" ID="Requiredfieldvalidator2"<BR>ErrorMessage="'Year End ' field is required! Use yyyy format (Note: present school should has 'present' value)" /><BR></EditItemTemplate><BR></asp:TemplateColumn><BR></Columns><BR><PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle><BR></asp:datagrid><BR><BR>might be a stupid question<BR><BR>but did you compile? it sounds like the ASP.NET dll doesn't know where to find that event handlerHi MorningZ...<BR><BR>STUPID ME..... :-) .. <BR><BR>It is a sort of 'not compiling correctly' .. <BR>What happen was I have duplicate copy of the same file in the same project(I'm using VStudio) but with different name.<BR><BR>I guess ASP.net is confused on these duplicate copy.<BR><BR>What I did was, I completely delete that other duplicate copy.<BR><BR>Then I had another problem... on Datagrid not able to access the <BR>"myDataGrid_OnItemDataBound" funtion. I solve the problem by changing the function attribute to public instead of private.. <BR><BR>VOILA' SOLVE THE PROBLEM!!!!!!!!!!!!! <BR><BR>THANKS FOR YOUR COMMENTSSSSSS<BR>
 
Back
Top