Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.code

XML
<%@ Page Title="" Language="C#" MasterPageFile="~/home.master" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .auto-style15 {
            width: 91px;

        }
        .auto-style16 {
            width: 91px;
            height: 23px;

        }
        .auto-style17 {
             height: 23px;

             border: 2px solid #a1a1a1;
             border-radius:5px;
             margin-top:50px;
             margin-left:300px;
             padding-left:0;
        }
        .auto-style18 {
            width: 235px;
        }
        .auto-style19 {
            width: 235px;

            height: 23px;
        }
        .auto-style20 {
            width: 91px;
            height: 26px;

        }
        .auto-style21 {
            width: 235px;

            height: 26px;
        }
        .auto-style22 {
            width: 91px;
            height: 37px;
        }
        .auto-style23 {
            width: 235px;
            height: 37px;
            margin-left: 40px;
        }
        .grid{
          margin-left:150px;
          margin-top:50px;
        }
         .activex{
          margin-left:150px;
          margin-top:30px;
        }

    </style>
    <script type="text/javascript">
function Confirmationbox() {
var result = confirm('Are you sure you want to delete selected User(s)?');
if (result) {
return true;
}
else {
return false;
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <table class="auto-style17">
        <tr>
            <td class="auto-style15" align="center">username</td>
            <td class="auto-style18" >
                <asp:TextBox ID="TextBox2" runat="server" Width="171px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style20" align="center">password</td>
            <td class="auto-style21">
                <asp:TextBox ID="TextBox3" runat="server" Width="171px" TextMode="Password"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style16" align="center">confirm mail</td>
            <td class="auto-style19">
                <asp:TextBox ID="TextBox4" runat="server" Width="171px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style15" align="center">upload image</td>
            <td class="auto-style18">
                <asp:FileUpload ID="FileUpload1" runat="server"/>
            </td>
        </tr>
        <tr>
            <td class="auto-style15">&nbsp;</td>
            <td class="auto-style18">&nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style22"></td>
            <td class="auto-style23">
                <asp:Button ID="Button1" runat="server" Text="Submit"  Width="65px" OnClick="Button1_Click1" />
                <asp:Button ID="Button2" runat="server" style="margin-left: 14px" Text="Reset" />
            </td>
        </tr>
        <tr>
            <td class="auto-style22">&nbsp;</td>
            <td class="auto-style23">
                <asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
            </td>
        </tr>
    </table>
    <div class="activex">
        <table><tr>
            <td>
        <asp:TextBox ID="TextBox1" runat="server" placeholder="Search id"></asp:TextBox>
                <td>
            <td>
        <asp:Button ID="Button3" runat="server" Text="Delete" OnClientClick="javascript:validateCheckBoxes()" OnClick="Button3_Click"/>
        </td>
                    </tr>

        </table>
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="userid" DataSourceID="SqlDataSource1" Width="608px" CssClass="grid" AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">


            <Columns>
                <asp:TemplateField>
        <HeaderTemplate>
        <asp:CheckBox ID="chkheader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server"/>
</ItemTemplate>
        <HeaderStyle HorizontalAlign="right" />
<ItemStyle HorizontalAlign="right" />
        </asp:TemplateField>
                <asp:BoundField DataField="userid" HeaderText="userid" InsertVisible="False" ReadOnly="True" SortExpression="userid" />
                <asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
                <asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
                <asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />
                <asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />
                <asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage">
                    <ControlStyle Width="100%" Height="100%"/>
                </asp:ImageField>
            </Columns>
            <FooterStyle BackColor="White" ForeColor="#000066" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
            <RowStyle ForeColor="#000066" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#007DBB" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#00547E" />
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:prakashConnectionString %>" SelectCommand="SELECT * FROM [getezeeregister] order by userid desc" DeleteCommand="delete from [getezeeregister] where userid= @userid">

    <DeleteParameters>
        <asp:Parameter Name="userid"/>
         <asp:Parameter Name="username"/>
         <asp:Parameter Name="password"/>
         <asp:Parameter Name="mail"/>
         <asp:Parameter Name="imagename"/>
        <asp:Parameter Name="uploadimage"/>
    </DeleteParameters>

    </asp:SqlDataSource>
</asp:Content>



C# code


C#
protected void Button3_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection("Data Source=MAC-20;Initial Catalog=prakash;User ID=****;Password=*******");
        con.Open();
        cmd = new SqlCommand("delete from getezeeregister where userid=@userid",con);
        cmd.ExecuteNonQuery();
        con.Close();
    }
Posted

i m using this code


C#
protected void Page_Load(object sender, EventArgs e)
   {

       Button3.Attributes.Add("onclick", "javascript:return Confirmationbox()");

   }



protected void Button3_Click(object sender, EventArgs e)
   {



       foreach (GridViewRow gvrow in GridView1.Rows)
       {

           CheckBox chkchild = (CheckBox)gvrow.FindControl("chkchild");

           if (chkchild.Checked)
           {
               int usrid = Convert.ToInt32(GridView1.DataKeys[gvrow.RowIndex].Value);
               SqlDataSource1.DeleteParameters["userid"].DefaultValue = usrid.ToString();
               SqlDataSource1.Delete();
           }
       }
   }
 
Share this answer
 
Type is missing from your Delete Parameter tag

<asp:parameter name="userid" type="Int32" xmlns:asp="#unknown">

try this
 
Share this answer
 
Comments
Member 10918596 21-Aug-14 5:25am    
xmlns:asp="#unknown" what is this?
You are missing the parameter for @userid
add it like this
C#
cmd.Parameters.AddWithValue("@userid", UserID);
 
Share this answer
 
v2
Comments
Member 10918596 21-Aug-14 5:24am    
here i am using delete command..
Dilan Shaminda 21-Aug-14 5:48am    
you haven't mentioned it before :-) then you can pass parameters like this from .cs
SqlDataSource1.SelectParameters.Add("userid", DbType.String, UserID);

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