zimmer9
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(obje ct 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="grdBa nkUpd_Page IndexChang ing"
OnRowUpdating="grdBankUpd_ RowUpdatin g"
OnRowEditing="grdBankUpd_R owEditing" OnRowCancelingEdit="grdBan kUpd_RowCa ncelingEdi t"
Font-Bold="True" Font-Size="Medium"
onselectedindexchanged="gr dBankUpd_S electedInd exChanged"
OnRowDeleting="grdBankUpd_ RowDeletin g"
EmptyDataText="there is no data"
onrowcommand="grdBankUpd_O nRowComman d">
<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:RegularExpressionVali dator ID="BankValidator" ValidationGroup="update" ControlToValidate="txtBank num" runat="server"
ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
ValidationExpression="^\d{ 4}$" ></asp:RegularExpressionVa lidator>
<asp:RequiredFieldValidato r id="Bankreqiredval" ValidationGroup="update" SetFocusOnError="true" runat="server"
ControlToValidate="txtBank num"
ErrorMessage="Bank Number is a required field."
ForeColor="Red">
</asp:RequiredFieldValidat or>
</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:RegularExpressionVali dator ID="fBankregValidator" ControlToValidate="ftxtBan knum" ValidationGroup="add" runat="server"
ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
ValidationExpression="^\d{ 4}$" ></asp:RegularExpressionVa lidator>
<asp:RequiredFieldValidato r id="fBankreqiredval" SetFocusOnError="true" ForeColor="Red" ValidationGroup="add" runat="server"
ControlToValidate="ftxtBan knum"
ErrorMessage="Bank Number is a required field.">
</asp:RequiredFieldValidat or>
<div id="divBanknum" class="error">
</div>
</FooterTemplate>
<ItemStyle HorizontalAlign="Left"></I temStyle>
</asp:TemplateField>
protected void grdBankUpd_RowEditing(obje
{
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"
Height="10%" PageSize="25" OnPageIndexChanging="grdBa
OnRowUpdating="grdBankUpd_
OnRowEditing="grdBankUpd_R
Font-Bold="True" Font-Size="Medium"
onselectedindexchanged="gr
OnRowDeleting="grdBankUpd_
EmptyDataText="there is no data"
onrowcommand="grdBankUpd_O
<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=
<EditItemTemplate>
<asp:TextBox ID="txtBanknum" MaxLength="6" runat="server" ReadOnly="true" Text='<%# Eval("bankID") %>'></asp:TextBox>
<asp:RegularExpressionVali
ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
ValidationExpression="^\d{
<asp:RequiredFieldValidato
ControlToValidate="txtBank
ErrorMessage="Bank Number is a required field."
ForeColor="Red">
</asp:RequiredFieldValidat
</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:RegularExpressionVali
ErrorMessage="4 digits with leading zeros." Display="Dynamic" SetFocusOnError="true" ForeColor="Red"
ValidationExpression="^\d{
<asp:RequiredFieldValidato
ControlToValidate="ftxtBan
ErrorMessage="Bank Number is a required field.">
</asp:RequiredFieldValidat
<div id="divBanknum" class="error">
</div>
</FooterTemplate>
<ItemStyle HorizontalAlign="Left"></I
</asp:TemplateField>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.