Pages

DotNet

Complete Grid View
HTML CODE

<asp:GridView ID="gvemp" runat="server" Width="100%" AutoGenerateColumns="False"
                                        AlternatingRowStyle-BackColor="LightBlue" ForeColor="#333333" CellSpacing="1"
                                        AllowPaging="True" OnRowEditing="gvemp_RowEditing" PageSize="10" OnRowUpdating="gvemp_RowUpdating"
                                        OnPageIndexChanging="gvemp_PageIndexChanging" OnRowCancelingEdit="gvemp_RowCancelingEdit">
                                        <RowStyle BackColor="#EFF3FB" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="Login ID">
                                                <EditItemTemplate>
                                                    <%--   <asp:TextBox ID="lbleditloginid" runat="server" Text='<%# Eval("LoginID") %>'></asp:TextBox>--%>
                                                    <asp:Label ID="lbleditloginid" runat="server" Text='<%# Eval("LoginID") %>'></asp:Label>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblloginid" runat="server" Text='<%# Eval("LoginID") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="First Name">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtfirstname" runat="server" Text='<%# Eval("FirstName") %>' MaxLength="20"
                                                        ValidationGroup="updatenull"></asp:TextBox>
                                                    <br />
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator4" ControlToValidate="txtfirstname"
                                                        ErrorMessage="Please enter your First Name !" ValidationGroup="updatenull" />
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator101" runat="server" ErrorMessage="Only Alphabets Allowed."
                                                        ControlToValidate="txtfirstname" ValidationExpression="^[a-zA-Z ]+$" ValidationGroup="null"></asp:RegularExpressionValidator>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblfirstname" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Last Name">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtlastname" runat="server" Text='<%# Eval("LastName") %>' MaxLength="20"
                                                        ValidationGroup="updatenull"></asp:TextBox>
                                                    <br />
                                                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="txtlastname"
                                                        ErrorMessage="Please enter your Last Name !" ValidationGroup="updatenull" />
                                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator102" runat="server" ErrorMessage="Only Alphabets Allowed."
                                                        ControlToValidate="txtlastname" ValidationExpression="^[a-zA-Z ]+$" ValidationGroup="null"></asp:RegularExpressionValidator>
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lbllastname" runat="server" Text='<%# Eval("LastName") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Active Status">
                                                <EditItemTemplate>
                                                    <asp:CheckBox ID="chkeditactive" runat="server" Checked='<%# Eval("Active") %>' />
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="chkdisable" runat="server" Checked='<%# Eval("Active") %>' Enabled="false" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Edit">
                                                <EditItemTemplate>
                                                    <asp:Button ID="btnupdate" runat="server" Text="Update" CommandName="Update" ValidationGroup="updatenull"
                                                        CausesValidation="true" />
                                                    <asp:Button ID="btnclose" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
                                                </EditItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Button ID="btnedit" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <%--  <asp:TemplateField HeaderText="Product Image">
                                                <ItemTemplate>
                                                    <asp:Button ID="btndelete" runat="server" Text="Delete" CausesValidation="true"/>
                                                </ItemTemplate>
                                            </asp:TemplateField>--%><%--<asp:CommandField ButtonType="Button" ShowDeleteButton="True" />--%>
                                        </Columns>
                                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                        <EditRowStyle BackColor="#FFFFCC" />
                                        <AlternatingRowStyle BackColor="White" />
                                    </asp:GridView>


=================================================================================================================
 .CS CODE

public void BindGV()
    {
       
      cn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd = new SqlCommand("select * from Users order by CreateDate Desc", cn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        daAdmin.Fill(ds);
      
        gvadmin1.DataSource = ds;
        gvadmin1.DataBind();
        cn.Close();
    }


protected void gvemp_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvemp.EditIndex = e.NewEditIndex;
        BindGV();
    }
    protected void gvemp_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox lblfirstname = (TextBox)gvemp.Rows[e.RowIndex].FindControl("txtfirstname");
        TextBox lbllastname = (TextBox)gvemp.Rows[e.RowIndex].FindControl("txtlastname");
        System.Web.UI.WebControls.Label lblloginid = (System.Web.UI.WebControls.Label)gvemp.Rows[e.RowIndex].FindControl("lbleditloginid");
        System.Web.UI.WebControls.CheckBox chkactive = (System.Web.UI.WebControls.CheckBox)gvemp.Rows[e.RowIndex].FindControl("chkeditactive");

        objadmin.Active = Convert.ToString( chkactive.Checked);
        objadmin.FirstName = lblfirstname.Text;
        objadmin.LastName = lbllastname.Text;
        objadmin.LoginID = lblloginid.Text;
        objadmin.updateAdmin();
        gvemp.EditIndex = -1;
        BindGV();
    }
    protected void gvemp_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvemp.PageIndex = e.NewPageIndex;
        BindGV();
    }

    protected void gvemp_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvemp.EditIndex = -1;
        BindGV();
    }

DATE SPLIT

   string todaydate= system.datetime.now();
                string[] words = todaydate.Split('-');

                ddlyear.SelectedValue = words[2].ToString();
                ddlmonth.SelectedIndex = int.Parse(words[1].ToString()) - 1;
                ddlday.Text = words[0].ToString();