Set ASP.Net GridView row add limit based on DropDownList value using C# and VB.Net

Last Reply one year ago By pandeyism

Posted one year ago

I have dropdown in which two type NinePack and SixPack , i want to control row limit in gridview using dropdownlist list type. if user will access then show message.

i am inserting row into gridview from textboxes using viewstate.Now i want, when i select NinePack From dropdownlist then in gridview restrict user not to insert more then nine row record or greater then Nine Line same in sixpack when i select sixpack in dropdownlist then six row can be added from textbox.

Pleae guide here is html of gridview.

<div>
    Ref No.
    <asp:TextBox ID="txtRefno" CssClass="form-control input-lg" Placeholder="Ref No"
        runat="server" OnTextChanged="txtRefno_TextChanged" AutoPostBack="True"></asp:TextBox>
    &nbsp; Order No.
    <asp:TextBox ID="txtOrder" CssClass="form-control input-lg" Placeholder="Order No"
        runat="server" Height="16px" Width="68px" AutoPostBack="true" OnTextChanged="txtOrder_TextChanged"></asp:TextBox>
    <asp:Label ID="lbmsg" runat="server" Text="." Font-Bold="True" Font-Size="Large"
        ForeColor="Red"></asp:Label>
    &nbsp;&nbsp;
    <asp:TextBox ID="txtpackno" CssClass="form-control input-lg" Placeholder="Order No"
        AutoPostBack="true" Visible="false" runat="server" Height="16px" Width="68px"
        OnTextChanged="txtpackno_TextChanged"></asp:TextBox>
    Order Qty :
    <asp:Label ID="lborderqty" runat="server" Text="." Font-Bold="True" Font-Size="X-Large"></asp:Label>
    Produce Qty :
    <asp:Label ID="lbprdqty" runat="server" Text="." Font-Bold="True" Font-Size="X-Large"></asp:Label>
    Packs Qty :
    <asp:Label ID="lbpkqty" runat="server" Text="." Font-Bold="True" Font-Size="X-Large"></asp:Label>
    Pending Qty :
    <asp:Label ID="lbpendingqty" runat="server" Text="." Font-Bold="True" Font-Size="X-Large"></asp:Label>
    <br />
    Packs Type :
    <asp:DropDownList ID="DDLPktype" runat="server">
        <asp:ListItem>NinePack</asp:ListItem>
        <asp:ListItem>SixPack</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server" Placeholder="Input Bale No"
        OnTextChanged="TextBox1_TextChanged" Height="16px" Width="100px" Style="margin-left: 0px"></asp:TextBox>
    <asp:DropDownList ID="DropDownList1" runat="server" Enabled="false" Height="20px"
        Width="130px">
    </asp:DropDownList>
    <asp:TextBox ID="txtorderno" Placeholder="Order No" ReadOnly="true" runat="server"
        Height="16px" Width="51px"></asp:TextBox>
    <asp:TextBox ID="txtqty" Placeholder="QTY" ReadOnly="true" runat="server" Height="16px"
        Width="56px"></asp:TextBox>
    &nbsp;
    <asp:Button ID="Button1" runat="server" Text="Add" Visible="false" OnClick="Button1_Click"
        Height="26px" Width="35px" />
    <asp:Label ID="Label1" runat="server" Text="." ForeColor="#CC0000"></asp:Label>
    <asp:Label ID="lbgvck" runat="server" Text="." ForeColor="#CC0000"></asp:Label>
    <asp:Label ID="lbpk" runat="server" Text="."></asp:Label>
    &nbsp;
</div>
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#66ccff" HeaderStyle-ForeColor="White"
    CssClass="mygrdContent" PagerStyle-CssClass="pager" HeaderStyle-CssClass="header"
    RowStyle-CssClass="rows" AutoGenerateColumns="false" OnRowDeleting="GridView1_RowDeleting"
    OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" AllowSorting="True"
    OnRowDataBound="GridView1_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="Bale_No">
            <ItemTemplate>
                <asp:Label ID="Prdno" runat="server" Text='<%#Bind("Prdno")%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Description">
            <ItemTemplate>
                <asp:Label ID="Descriptionitem" runat="server" Text='<%#Bind("Descriptionitem")%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Orderno">
            <ItemTemplate>
                <asp:Label ID="Orderno" runat="server" Text='<%#Bind("Orderno")%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="QTY">
            <ItemTemplate>
                <asp:Label ID="QTY" runat="server" Text='<%#Bind("QTY")%>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
    </Columns>
    <HeaderStyle BackColor="#66CCFF" ForeColor="White"></HeaderStyle>
    <SelectedRowStyle BackColor="Yellow" />
</asp:GridView>

 

 

This question does not have replies that have been liked.