Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am list all the project name with edit and delete option on datalist. I am used conformation box for delete button.Its worked.But when i clicked yes then the Project id is not passed via query string... I need to delete the particular project from database through that project id... How can i pass that id when user clicks yes on conformation box?


ASPX FILE:

XML
<script type="text/javascript">
     //Confirmation box sample
     function ConfirmationBox() {
         var result = confirm("Are you sure you want to Delete?");
         if (result == true)
         {
             return true;
         }
         else {
             var lbl = document.getElementById('Resultlbl');
             lbl.innerHTML = "";
             return false;
         }
     }
          
<pre lang="xml"><asp:DataList ID="DataList1" runat="server" >
               <ItemTemplate>
               <table cellpadding="15" cellspacing="15" width="700px">
               <tr>
               <td class="Subheadfont" width="80%"><%# Eval("ProjectName")%></td>
               <td width="10%"><a href="Edit_Project.aspx?Proid=<%# Eval("ProjectID") %>">Edit</a></td><td width="10%"><a href="List Of Projects.aspx?Proid=<%#Eval("ProjectID")%>">
                   <asp:Button ID="BtnDelete" runat="server" OnClientClick="return ConfirmationBox()" onclick="btnSubmit_Click" Text="Delete"></asp:Button></a></td>
               </tr>
              <%-- <tr><td><a href="FullProjectDetails.aspx?Proid=<%# Eval("ProjectID") %>">
               <img src="Admin/ProImages/<%# Eval("Image1") %>" width="180px" alt="" height="150px" /></a>
               </td> </tr>--%>
               </table>
               </ItemTemplate>
               </asp:DataList>



ASPX.CS File:

public partial class ListAllProjects : System.Web.UI.Page
{
    Admin Objadmin = new Admin();
    int proid;
    protected void Page_Load(object sender, EventArgs e)
    {
        BindProjects();    
    }

    public void BindProjects()
    {
        DataSet ds = new DataSet();
        ds = Objadmin.View_All_Projects();
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        proid = Convert.ToInt32(Request.QueryString["Proid"]);

        if (proid > 0)
        {
           // Delete Record in Database

            String check = Objadmin.Delete_Project(proid);
            if (check == "yes")
            {
                Resultlbl.Visible = true;
                Resultlbl.Text = "Project Deleted Successfully!";
                BindProjects();
            }
            else
            {
                Resultlbl.Visible = true;
                Resultlbl.Text = "Project Not Deleted!";
            }
        }
        else
        {

            BindProjects();
        }
    }
}
Posted
Updated 4-Jul-13 2:25am
v4

1 solution

On the Edit_Project.aspx or List Of Projects.aspx you can easily get the ProID via querystring and Edit/delete it.
 
Share this answer
 
Comments
SnvMohan 5-Jul-13 0:31am    
I tried....but query string didnt get id........
[no name] 5-Jul-13 4:11am    
If you are'nt getting values in table or null in query string then you need to debug.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900