Hi nauna,
Check this sample. now take its reference and correct your code.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function CheckDebitCredit(ele) {
var debit = $(ele).closest('div.row').find('[id*=txtDebit]');
var credit = $(ele).closest('div.row').find('[id*=txtCredit]');
if ($(ele).val() != '') {
if ($(ele).attr('id') == $(debit).attr('id')) {
$(credit).attr('readonly', 'readonly');
} else if ($(ele).attr('id') == $(credit).attr('id')) {
$(debit).attr('readonly', 'readonly');
}
} else if ($(ele).attr('id') == $(debit).attr('id')) {
$(credit).removeAttr('readonly');
} else if ($(ele).attr('id') == $(credit).attr('id')) {
$(debit).removeAttr('readonly');
}
}
</script>
<div>
<div class="form-group padding10">
<div class="row ">
<div class="col-md-3 padding5">Account</div>
<div class="col-md-4 padding5">Description</div>
<div class="col-md-2 padding5 right">Debit</div>
<div class="col-md-2 padding5 right">Credit</div>
<div class="col-md-1 padding5">
</div>
</div>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%#Eval("ID") %>' Visible="true"></asp:Label>
<div class="row ">
<div class="col-md-4 padding5">
<asp:TextBox ID="txtDescription" runat="server" Text='<%#Eval("Description") %>'></asp:TextBox></div>
<div class="col-md-2 padding5">
<asp:TextBox ID="txtDebit" runat="server" Text='<%#Eval("Debit") %>' placeholder="Debit"
onkeyup="CheckDebitCredit(this);"></asp:TextBox>
<asp:TextBox ID="txtCredit" runat="server" Text='<%#Eval("Credit") %>' placeholder="Credit"
onkeyup="CheckDebitCredit(this);"></asp:TextBox>
</div>
<div class="col-md-1 padding5">
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="del" OnClientClick="return confirm('Are you sure you want to delete ?')"><i class="fas fa-times margin10 grey-c"></i></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</div>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("Description", typeof(string)),
new System.Data.DataColumn("Debit",typeof(string)),
new System.Data.DataColumn("Credit",typeof(string)) });
dt.Rows.Add(1, "Description 1", "", "");
dt.Rows.Add(2, "Description 2", "", "");
ListView1.DataSource = dt;
ListView1.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {
New System.Data.DataColumn("Id", GetType(Integer)),
New System.Data.DataColumn("Description", GetType(String)),
New System.Data.DataColumn("Debit", GetType(String)),
New System.Data.DataColumn("Credit", GetType(String))})
dt.Rows.Add(1, "Description 1", "", "")
dt.Rows.Add(2, "Description 2", "", "")
ListView1.DataSource = dt
ListView1.DataBind()
End If
End Sub