| |

VerySource

 Forgot password?
 Register
Search
View: 683|Reply: 6

There is a checkbox and label in the datalist. How to get the value of the label of the datalist when the checkbox is se

[Copy link]

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-22 11:00:01
| Show all posts |Read mode
Ibid
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-2-1 23:09:01
| Show all posts
datalist.Items [i] .FondControl ("lableId")
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-2-2 11:54:01
| Show all posts
There are many columns. How can I get the value of i?
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-6 13:45:01
| Show all posts
Add a click event to the checkbox when binding the datalist.
e.Item.FondControl ("checkBoxID"). Attributes.Add ("onclick", "doSomeThing ('" + e.Item.FondControl ("lableId"). ClientID + "'");
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-2-16 15:30:02
| Show all posts
The above method does not work, is there any?
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-3-18 22:45:01
| Show all posts
Hehe, I wrote a bit wrong, I modified it, the test was successful, remember to check out in time:
<asp: DataList id = "DataList1" runat = "server" OnItemDataBound = "init">
<ItemTemplate>
<asp: CheckBox ID = t1 Runat = server />
<asp: Label ID = l1 Runat = server>
<% # DataBinder.Eval (Container.DataItem, "b")%> </ asp: Label>
</ ItemTemplate>
</ asp: DataList>
<script language = javascript>
function doSomeThing (objName) {
  alert (document.getElementById (objName) .innerHTML);
};
</ script>


Here is the background code:
public void init (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
CheckBox cb1 = (CheckBox) (e.Item.FindControl ("t1"));
Label lb = (Label) (e.Item.FindControl ("l1"));
cb1.Attributes.Add ("onclick", "doSomeThing ('" + lb.ClientID + "');");
}
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-19 19:45:02
| Show all posts
for (int i = 0; i <DataList1.Items.Count; i ++)
        {
            CheckBox chk1 = (CheckBox) DataList1.Items [i] .FindControl ("CheckBox1");
            if (chk1.Checked)
            {
              Label lb = (Label) DataList1.Items [i] .FindControl ("Label1");
            }
        }
   Response.Write (lb.Text);
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