Hi
In a list i am displaying only 4-5 fields but there are more fields. How i will get the values of other fields on click of Edit button
C#
htmlTable.Append("");
htmlTable.Append("Sr.CodeDescriptionSwift CodeStatusAction");
htmlTable.Append("");
foreach (DataRow row in dt.Rows)
{
String Status = "Blocked";
if (Convert.ToBoolean(row["status"]))
{
Status = "Active";
}
htmlTable.Append("");
htmlTable.Append("" + Count.ToString() + "");
htmlTable.Append("" + row["bankcode"] + "");
htmlTable.Append("" + row["bankname"] + "");
htmlTable.Append("" + row["swiftcode"] + "");
htmlTable.Append("");
htmlTable.Append("");
//string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' onclick='BindData(this);'";
string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' ";
htmlTable.Append($"");
htmlTable.Append("");
htmlTable.Append("" + row["docentry"] + "");
htmlTable.Append("" + row["status"] + "");
htmlTable.Append("");
Count++;
}
htmlTable.Append("");
htmlTable.Append("");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });Thanks

Aman GuptaRank #193 · 12.4K reputationPosted Aug 28, 2024, 12:42 PM EDT
Hi Ramco,
To access additional fields (like docentry and status) when clicking the "Edit" button, you can store these values in data-* attributes within the HTML element. This allows you to pass all the necessary information to your JavaScript function when the user clicks the "Edit" button. Here's how you can modify your code:
Step 1: Add data-* Attributes for the Hidden Fields
You can modify the htmlTable.Append code to include data-* attributes for the hidden fields:
foreach (DataRow row in dt.Rows) { String Status = "Blocked"; if (Convert.ToBoolean(row["status"])) { Status = "Active"; } htmlTable.Append(""); htmlTable.Append("" + Count.ToString() + ""); htmlTable.Append("" + row["bankcode"] + ""); htmlTable.Append("" + row["bankname"] + ""); htmlTable.Append("" + row["swiftcode"] + ""); htmlTable.Append(""); // Add data-* attributes to store hidden field values htmlTable.Append($""); string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete'"; htmlTable.Append($""); htmlTable.Append(""); htmlTable.Append("" + row["docentry"] + ""); htmlTable.Append("" + row["status"] + ""); htmlTable.Append(""); Count++; }Step 2: Update the BindData JavaScript Function
Modify your BindData JavaScript function to retrieve the values from these data-* attributes:
function BindData(element) { var docentry = $(element).data('docentry'); var status = $(element).data('status'); var bankcode = $(element).data('bankcode'); var bankname = $(element).data('bankname'); var swiftcode = $(element).data('swiftcode'); // Now you can populate your modal fields or perform any other actions with these values $('#modal_form_horizontal').find('#txtDocEntry').val(docentry); $('#modal_form_horizontal').find('#txtStatus').val(status); $('#modal_form_horizontal').find('#txtBankCode').val(bankcode); $('#modal_form_horizontal').find('#txtBankName').val(bankname); $('#modal_form_horizontal').find('#txtSwiftCode').val(swiftcode); }Step 3: Ensure Your Modal Has the Corresponding Fields
Make sure your modal form (#modal_form_horizontal) has the appropriate fields (e.g., #txtDocEntry, #txtStatus, #txtBankCode, #txtBankName, #txtSwiftCode) where you want to populate the data:
Explanation
With this approach, you can easily pass and retrieve all necessary data when the "Edit" button is clicked, even if those fields are not directly displayed in the table.
Ramco RamcoRank #462 · 5.4K reputationPosted Aug 28, 2024, 9:15 PM EDT
Hi Aman
How i will access other fields like address1,address2,city,state,pin etc . I am not displaying in the list.
Thanks