| |

VerySource

 Forgot password?
 Register
Search
Author: vincentngacn

Please explain some code just now, thank you

[Copy link]

2

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-26 19:15:01
| Show all posts
Suddenly there was another problem:
Now only one line of detail can be displayed,
(That is, when you click on another line, the previous line will naturally disappear)
Then I want to show the details when I click on each line
The details are not hidden until the point is hidden
Such as
 --------------------
| id | Name | Total business results |
 --------------------
| 1 | Xiao Zhang | 100000 | detail |
 --------------------
| 2 | Xiao Wang | 20000 | Details |
 --------------------
| Software Engineering | 06-01-12 | 8000 |
 --------------------
| Website Development | 06-11-10 | 12000 |
 --------------------
| 3 | Xiao Li | 80000 | Detail |
 --------------------
| Software Engineering | 06-01-12 | 8000 |
 --------------------
| Website Development | 06-11-10 | 12000 |
 --------------------
Such an effect
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-26 23:30:01
| Show all posts
This is another way I said.
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-26 23:45:01
| Show all posts
<asp: GridView AutoGenerateColumns = "false" ID = "GridView1" runat = "server" OnRowDataBound = "GridView1_RowDataBound" OnRowCommand = "GridView1_RowCommand">
            <Columns>
                <asp: BoundField DataField = "Key" HeaderText = "Key" />
                 <asp: BoundField DataField = "Value" HeaderText = "Value" />
                 
                 <asp: TemplateField>
                    <ItemTemplate>
                        <input type = "button" value = "Show" onclick = "GoShowDetail (this, 1);" />
                        <input type = "button" value = "hide" onclick = "GoShowDetail (this, 2);" />
                    </ ItemTemplate>
                 </ asp: TemplateField>
               
              
            </ Columns>
        </ asp: GridView>

<asp: Repeater ID = "rp1" runat = "server">
            <HeaderTemplate>
                <table border = "1">
                <tr>
                    <td> Category </ td>
                    <td> Time </ td>
                    <td> Amount </ td>
                </ tr>
            </ HeaderTemplate>
            <ItemTemplate>
                <TR>
                    <td> <% # Eval ("A")%> </ td>
                     <td> <% # Eval ("B")%> </ td>
                     <td> <% # Eval ("C")%> </ td>
                </ TR>
            </ ItemTemplate>
            <FooterTemplate>
                </ TABLE>
            </ FooterTemplate>
        </ asp: Repeater>




<script type = "text / javascript">
 function GoShowDetail (btn, i)
 {
    var tr = btn.parentElement.parentElement.nextSibling;
    
    tr.style.display = (i == 1)? "" :: "none";
 }
</ script>
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-27 00:15:01
| Show all posts
Backstage:
Remove the original rowcommand event.


    protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
    {
       
        
        GridViewRow row = e.Row;
        GridViewRow NewRow = new GridViewRow (0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
        NewRow.Cells.Add (new TableCell ());
        NewRow.Cells [0] .ColumnSpan = row.Cells.Count;
        //NewRow.Cells[0].Controls.Add(this.rp1);
        NewRow.Style.Add ("display", "none");

        DataTable dt = new DataTable ();
        dt.Columns.Add ("A", typeof (string));
        dt.Columns.Add ("B", typeof (string));
        dt.Columns.Add ("C", typeof (Int32));
        DataRow r1 = dt.NewRow ();
        r1 [0] = "Software Engineering";
        r1 [1] = "06-01-12";
        r1 [2] = 8000;
        dt.Rows.Add (r1);
        r1 = dt.NewRow ();
        r1 [0] = "Website Development";
        r1 [1] = "06-11-10";
        r1 [2] = 12000;
        dt.Rows.Add (r1);


        this.rp1.DataSource = dt.DefaultView;
        this.rp1.DataBind ();



        this.GridView1.Controls [0] .Controls.Add (NewRow);
        //this.rp1.RenderControl(Html32TextWriter);
        System.Text.StringBuilder sb = new System.Text.StringBuilder ();
        Html32TextWriter tr = new Html32TextWriter (new System.IO.StringWriter (sb));
        this.rp1.RenderControl (tr);
        NewRow.Cells [0] .Text = sb.ToString ();
    }
Reply

Use magic Report

2

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-27 02:45:01
| Show all posts
Sorry, this is all loaded at the time of loading
Is it possible to load the corresponding record when the user clicks on the display

Sorry sorry
Reply

Use magic Report

2

Threads

11

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-4-27 06:15:01
| Show all posts
Halo, this js is really clever. If it were me, it would have to go through the div name and take the div name
<script type = "text / javascript">
 function GoShowDetail (btn, i)
 {
    var tr = btn.parentElement.parentElement.nextSibling;
    
    tr.style.display = (i == 1)? "" :: "none";
 }
</ script>
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-27 09:00:02
| Show all posts
Sorry, this is all loaded at the time of loading
Is it possible to load the corresponding record when the user clicks on the display
===========
But it is possible, but it is more troublesome.

To write in the ItemCreated event, first make a mark in the command, then write in the command,
Only then can the generated html be saved.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-27 10:30:02
| Show all posts
What does he mark?
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-4-27 11:15:01
| Show all posts
What does he mark?
=======
Put a value in ViewState.

Personally think that it is better to display all on the client at once,
This avoids repeated submissions,
Because gridview has a limited number of rows with paging, the cost of generating HTML is not very large.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-27 12:30:01
| Show all posts
ViewState = "" id string
Then in RowDataBound determine whether the current binding ID is the same
Show

Then add this ID when you click display in rowcommand
Delete this ID when clicking hide

Is this the case
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list