Monday, April 4, 2016

Gridview inline Editing


  <td id="tblEditClick" runat="server" style="width:60%; border: 1px solid black" >
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="UID"
                            OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit"
                            OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
                            <Columns>
                                <asp:CommandField ShowDeleteButton="true"/>
                                <asp:CommandField ShowEditButton="true" />                                                            
                                <asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="true"/>
                                 <asp:BoundField DataField="FullControl" HeaderText="Full"/>
                                 <asp:BoundField DataField="Contribute" HeaderText="Write"/>
                                <asp:BoundField DataField="Read" HeaderText="Read"/>                               
                            </Columns>

                        </asp:GridView>


  protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                gvbind();
            }
        }

        protected void gvbind()
        {
            SPListItemCollection iColl = SPContext.Current.Web.Lists.TryGetList("RKU List").Items;
            DataTable dt = new DataTable();
            GridView1.DataSource = iColl.GetDataTable();
            GridView1.DataBind();

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label lbldeleteid = (Label)row.FindControl("lblID");
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            gvbind();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int userid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
            Label lblID = (Label)row.FindControl("lblID");
            //TextBox txtname=(TextBox)gr.cell[].control[];
            TextBox textName = (TextBox)row.Cells[0].Controls[0];
            TextBox textadd = (TextBox)row.Cells[1].Controls[0];
            TextBox textc = (TextBox)row.Cells[2].Controls[0];
            //TextBox textadd = (TextBox)row.FindControl("txtadd");
            //TextBox textc = (TextBox)row.FindControl("txtc");
            GridView1.EditIndex = -1;
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            gvbind();
        }
        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            gvbind();
        }
 ============================================

Gridview with CheckBox


  <asp:GridView ID="gvAllDocLibs" runat="server" Width="210px"
                            AutoGenerateColumns="false" OnRowCommand="gvAllDocLibs_RowCommand"
                            OnRowDeleting="gvAllDocLibs_RowDeleting" OnRowEditing="gvAllDocLibs_RowEditing">

                            <Columns>

                                <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="#007ACC">
                                    <ItemTemplate>
                                        <asp:Label ID="lblDtame" runat="server" Text='<%# Eval("DtRoomName") %>'> 
                                        </asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Is DataRoom?" HeaderStyle-ForeColor="#007ACC">
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkIsRoom" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsDataRoom")) %>' Enabled="false" />
                                    </ItemTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit"
                                            Text="Configure" CommandArgument=' <%# Eval("DtID") %>' Width="50px"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>

                            </Columns>
                        </asp:GridView>


------------------


No comments:

Post a Comment