0

I have a stored procedure that select data in my table.

USE [accounting2]
GO
/****** Object:  StoredProcedure [dbo].[Get_Remittance]    Script Date: 05/10/2017 09:32:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Get_Remittance]
as
SELECT 
    ID as '#'
    ,COMPNAME as 'Company Name'         
   ,[REMITTYPE] as 'Remittance Type'
   ,SCHEDPAY as 'Schedule Pay'
   ,CONVERT(varchar(10),[GEN_DATE], 101) AS 'Date Generated'
   ,CONVERT(varchar(10),[PAID_DATE], 101) AS 'Date Paid'
   ,CONVERT(varchar(10),[TRANS_DATE], 101) AS 'Date Transmitted'
   ,[MONTH] as 'Applicable Month'

  FROM [accounting2].[dbo].[GMB_REMITTANCE]

and this is the way how i populate data in my tablE (HTML Table) during page load.

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Display_RemittanceReport();

                string query = "Get_Remittance";
                DataTable dt = new CLS_SProd().ALLRemittance(query);
                StringBuilder html = new StringBuilder();


                html.Append("<table border = '1'>");
                html.Append("<tr>");
                html.Append("<th>");
                html.Append("");
                html.Append("</th>");
                foreach (DataColumn column in dt.Columns)
                {
                    html.Append("<th>");
                    html.Append(column.ColumnName);
                    html.Append("</th>");
                }
                html.Append("</tr>");


                foreach (DataRow row in dt.Rows)
                {
                    html.Append("<tr>");
                    html.Append("<td>");
                    //html.Append(@"<img src='Images\Pencil.ico' alt='' border=1 height=18 width=16 class='click - to - select'></img>");
                    html.Append("<a href='#'>Select</a>");
                    html.Append("</td>");
                    foreach (DataColumn column in dt.Columns)
                    {

                        html.Append("<td>");
                        html.Append(row[column.ColumnName]);
                        html.Append("</td>");
                    }
                    html.Append("</tr>");
                }


                html.Append("</table>");
                PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });

                Display_CompName();
            }
        }

Based on th code above i created a table based on my data and there will be always a link called select.

My question is how can i use that select to transfer current row in my textbox? and here is my textbox

<asp:TextBox ID="TextBox7" runat="server" OnTextChanged="TextBox7_TextChanged" ></asp:TextBox>

Updated Code

HTML

<title>GMB Monitoring System</title>
<script type="text/javascript">
    $('a[actor=popup]').on('click', function () {
        document.getElementById('TextBox21').value = $(this).closest('tr').find('td:eq(2)').text();
    });
</script>

<%-- and so on...... --%>

C#

 private void Display_Remittance()
        {
            //Display Remittance Report

            string query = "Get_Remittance";
            DataTable dt = new CLS_SProd().ALLRemittance(query);
            StringBuilder html = new StringBuilder();


            html.Append("<table border = '1'");
            html.Append("<tr>");
            html.Append("<th>");
            html.Append("Select");
            html.Append("</th>");
            foreach (DataColumn column in dt.Columns)
            {
                html.Append("<th>");
                html.Append(column.ColumnName);
                html.Append("</th>");
            }
            html.Append("</tr>");


            foreach (DataRow row in dt.Rows)
            {
                //Working Code
                //html.Append("<td>");
                //html.Append(@"<img src='Images\Pencil.ico' alt='' border=1 height=18 width=16 class='click - to - select'></img>");
                //html.Append("<a href='#'>Select</a>");
                // html.Append("<a actor='popup' href='#'>Select</a>");
                //html.Append("</td>");

                html.Append("<tr>");
                html.Append("<td><a actor='popup' href='#'>Select</a></td>");

                foreach (DataColumn column in dt.Columns)
                {
                    html.Append("<td>");
                    html.Append(row[column.ColumnName]);
                    html.Append("</td>");
                }
                html.Append("</tr>");
            }
            html.Append("</table>");
            PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
        }

TYSM

2
  • what do you want the textbox to show; The raw html? Commented May 10, 2017 at 2:28
  • yes sir the data inside of the html table Commented May 10, 2017 at 2:32

2 Answers 2

1

You can do something like this

html.Append("<td><a actor='popup' href='#'>Select</a></td>");

And than in javascript
1.] to Get nth cell value in cell

 $('a[actor=popup]').on('click', function () {
    document.getElementById('TextBox7').value = $(this).closest('tr').find('td:eq(2)').text();
  });


2.] to get whole row

 $('a[actor=popup]').on('click', function () {
    document.getElementById('TextBox7').value = $(this).closest('tr').text();
  });
Sign up to request clarification or add additional context in comments.

13 Comments

If you feel any problem in putting the code together in your file than let me know @Paul Edward Pagente
Let me try this and get back to you asap :)
Sir not working what happens is in the end of link there is an # but not trans. in textbox
trans ?? what actually you got is unclear , there is no value in textbox ??
i mean sir transfered, theres no value in textbox.
|
0

You could do it sever side by retrieving the specific row again from db based on some id but I would try a client side approach with JQuery.

Client side approach:

1) Add a unique id to each row E.g. id="row_1"

2) Write a JavaScript function that takes as a parameter the row id. Then using JQuery to access the contents of that specifc row copy the data to the textbox.

3) Add the JavaScript to call the function from each select link E.g. onclick="javascript:fill_function('row_1');"

2 Comments

Sir can you give me a code? Its hard for a beginner like me to understand this
can u pls assist me sir?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.