Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

In an ASP.NET C# application using .NetFramework 4.0, how would you resolve the following function to make the first column (txtBanknum) of a GRIDVIEW READONLY when the user is in EDIT mode?

In an ASP.NET C# application using .NetFramework 4.0, how would you resolve the following function to make the first column (txtBanknum) of a GRIDVIEW READONLY when the user is in EDIT mode?

 protected void grdBankUpd_RowEditing(object sender, GridViewEditEventArgs e)
 {
            lblStatus.Visible = true;
            lblStatus.Text = "";

            grdBankUpd.EditIndex = e.NewEditIndex;            
           
            binddata();
}

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

 <asp:GridView ID="grdBankUpd" runat="server" AllowPaging="True"
        ShowFooter="True" BackColor="White" BorderColor="#00356A"
        BorderWidth="2px" ForeColor="#00356A" HorizontalAlign="Center"
        ShowHeaderWhenEmpty="True" Width="100%" AutoGenerateColumns="False"
        Height="10%"  PageSize="25" OnPageIndexChanging="grdBankUpd_PageIndexChanging"
         
        OnRowUpdating="grdBankUpd_RowUpdating"
        OnRowEditing="grdBankUpd_RowEditing" OnRowCancelingEdit="grdBankUpd_RowCancelingEdit"                      
         Font-Bold="True" Font-Size="Medium"  
         onselectedindexchanged="grdBankUpd_SelectedIndexChanged"
          OnRowDeleting="grdBankUpd_RowDeleting"            
          EmptyDataText="there is no data"
          onrowcommand="grdBankUpd_OnRowCommand">    
       
        <RowStyle BackColor="#66FFFF" BorderColor="#00356A" BorderStyle="Double"
         BorderWidth="2px" Height="5%"  HorizontalAlign="Center" />
        <AlternatingRowStyle BackColor="White" BorderWidth="2px" Height="80%"
           ForeColor="#00356A" HorizontalAlign="Center" VerticalAlign="Middle" />
        <EditRowStyle BackColor="White" BorderColor="#00056A" BorderStyle="Double"
            BorderWidth="2px" ForeColor="#000356" Height="100%" HorizontalAlign="Center"
            VerticalAlign="Middle" Width="100%" />
            <PagerSettings Mode="NumericFirstLast" />
        <PagerStyle BackColor="#00356A" ForeColor="White" HorizontalAlign="Center"
            VerticalAlign="Middle" />
            <Columns>  
               
                 <asp:TemplateField HeaderText="Bank Number" ItemStyle-HorizontalAlign="Left">
                    <EditItemTemplate>                                        
                               <asp:TextBox ID="txtBanknum" MaxLength="6" runat="server" ReadOnly="true" Text='<%# Eval("bankID") %>'></asp:TextBox>
                     <asp:RegularExpressionValidator ID="BankValidator" ValidationGroup="update" ControlToValidate="txtBanknum" runat="server"
                        ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
                        ValidationExpression="^\d{4}$" ></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator id="Bankreqiredval" ValidationGroup="update" SetFocusOnError="true" runat="server"
                    ControlToValidate="txtBanknum"
                    ErrorMessage="Bank Number is a required field."
                    ForeColor="Red">
                    </asp:RequiredFieldValidator>                    
                    </EditItemTemplate>
                    <ItemTemplate>
                         <asp:Label ID="lblBanknum" runat="server" Text='<%# Eval("bankID") %>'></asp:Label>
                    </ItemTemplate>
               <FooterTemplate>
               <asp:TextBox ID="ftxtBanknum" Width="50px" MaxLength="4" MaximumValue="9999" MinimumValue="0001" runat="Server" Text='<%# Eval("bankID") %>'></asp:TextBox>                       
                     <asp:RegularExpressionValidator ID="fBankregValidator" ControlToValidate="ftxtBanknum" ValidationGroup="add" runat="server"
                        ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
                        ValidationExpression="^\d{4}$" ></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator id="fBankreqiredval" SetFocusOnError="true" ForeColor="Red" ValidationGroup="add" runat="server"
                    ControlToValidate="ftxtBanknum"
                    ErrorMessage="Bank Number is a required field.">                    
                    </asp:RequiredFieldValidator>
                   <div id="divBanknum" class="error">
                  </div>
                 </FooterTemplate>

<ItemStyle HorizontalAlign="Left"></ItemStyle>
                 </asp:TemplateField>
ASKER CERTIFIED SOLUTION
Avatar of Shalu M
Shalu M
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial