小编Con*_*Fan的帖子

如何使用ListItems初始化DropDownList

我正在尝试初始化DropDownList,这是我的select方法:

public List<ListItem> metodShownAbove()
{
    List<ListItem> initlist = new List<ListItem>();
    if (!IsPostBack)
    {
        initlist.Add(new ListItem("--- all---", "-1"));
        initlist.Add(new ListItem("text1", "Value1"));
        initlist.Add(new ListItem("text2", "Value2"));
        initlist.Add(new ListItem("text3", "Value3"));
    }
    return initlist;
}
Run Code Online (Sandbox Code Playgroud)

这是在我的aspx页面上:

<asp:DropDownList ID="DDL" runat="server" AutoPostBack="True" 
    SelectMethod="metodShownAbove"/> 
Run Code Online (Sandbox Code Playgroud)

initlist返回我想要返回的内容,文本和值,如上所示.但是,当我试图让所选择的值或文本,DDL.SelectedItem.Value并且DDL.SelectedItem.Text,它是相同的值,在列表项initlist第一个.DDL中没有包含"Value1"的属性.我做错了什么,如何正确插入值,以便我可以读取,值和文本?

asp.net drop-down-menu

5
推荐指数
1
解决办法
1120
查看次数

ASP.NET GridView:如何编辑和删除数据记录

嗨,我已经使用gridview创建一个表.有没有办法实现编辑和删除.我以前用PHP做过.我想要使​​用的方法是在表中再创建两列,每行包含编辑和删除按钮.然后,当单击按钮时,它会通过URL传递"id"并能够编辑或删除.不确定如何在asp.net webforms中执行此操作.下面是我的表格代码.谢谢.

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
    <asp:BoundField HeaderText="Surgery" DataField="surgery" />
    <asp:BoundField HeaderText="PatientID" DataField="patientID" />
    <asp:BoundField HeaderText="Location" DataField="location" />

</Columns>          
Run Code Online (Sandbox Code Playgroud)

SqlCommand cmd = new SqlCommand("select surgery, patientID, location from details", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);

conn.Close();

GridView1.DataSource = dt;
GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)

c# asp.net webforms aspxgridview

5
推荐指数
1
解决办法
1万
查看次数

Angular:嵌入,设置SVG元素的颜色

我有一个component.html嵌入我的 svg 组件的:

<masterflex-sidebar>
    <masterflex-logo sidebar-logo color="white">

    </masterflex-logo>
</masterflex-sidebar>
Run Code Online (Sandbox Code Playgroud)

我的logo.ts文件:

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'masterflex-logo',
  templateUrl: './masterflex.component.html',
  styleUrls: ['./masterflex.component.scss']
})
export class MasterflexComponent implements OnInit {

  @Input() color:string

  constructor() { }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

我的 svg 组件(其中的一部分):

<svg 
    version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    x="0px" y="0px"
    viewBox="0 0 237.4 35.9"
    height="35.9"
    width="237.4"
    xml:space="preserve" *ngIf="color">
Run Code Online (Sandbox Code Playgroud)

我希望能够将我的 svg 组件的颜色更改为我想要的任何颜色(在我的第一个组件中设置 color="white")并将该颜色应用于我的 svg。有没有办法将该颜色属性传递给 scss 样式?

css sass angular

5
推荐指数
1
解决办法
9882
查看次数

在 ngAfterViewInit 中检索由 ngFor 创建的元素

我正在我的 Angular (5) 应用程序中实现一个懒惰的图像加载器,并且很好奇如何避免setTimeout()ngAfterViewInit()可能的情况下调用我的.

代码的相关部分是:

# component
ngOnInit(): void {
  this.workService.getCategories().then(workCategories => {
    this.workCategories = workCategories;
  });
}

ngAfterViewInit(): void {
  setTimeout(() => {
    const images = Array.from(document.querySelectorAll('.lazy-image'));
  }, 100);
}

# component template
<div *ngFor="let workCategory of workCategories">
  <h3>{{ workCategory.fields.name }}</h3>
  <div *ngFor="let workSample of workCategory.fields.workSamples">
    <img width="294" height="294" class="lazy-image" src="..." data-src="..." />
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如果我删除setTimeout()图像数组始终为空。AfterViewInit应该在所有子组件创建后运行。我也尝试过 AfterContentInit,它的行为与 AfterContentChecked 相同,后者导致 Chrome 崩溃。

在这种情况下是否可以避免 setTimeout ?

javascript angular

5
推荐指数
1
解决办法
1872
查看次数

取消选中所有用* ngFor创建的复选框

我有一个表,该表的列包含使用的每一行的复选框*ngFor。单击按钮后,我要取消选中所有复选框。我尝试使用[(ngModel)]="boxChecked"每个复选框,并在我的按钮单击调用的方法中将该值设置为false,但是每当我仅选中其中一个复选框时,就会导致每个复选框都被选中。单击按钮并不会取消选中所有复选框,但是我仍然需要能够单独选中复选框。

<ng-template pTemplate="body" let-sub let-expanded="expanded" let-columns="columns">
      <tr [pSelectableRow]="subcontract">
        <td *ngFor="let col of columns" [ngSwitch]="true" style="text-align: center">
          <div *ngSwitchCase="col.export" ><input type="checkbox" (change)="checked($event, sub)" [(ngModel)]="boxChecked"></div>
        </td>
      </tr>
</ng-template>
<button type="button"(click)="reset(table)"></button>
Run Code Online (Sandbox Code Playgroud)

ts:

//I send the ID of the table to this method.
reset(table) {
    table.reset();
    this.boxChecked = false;
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,在我的研究中,我还没有看到表上有某种get(index i)(获取索引参数的单行)方法。然后,我可以轻松地遍历表并将每个迭代(行)的复选框设置为false。

angular

5
推荐指数
1
解决办法
3091
查看次数

如何处理鼠标中键的 Angular(单击)事件?

我有一个图标,用作打开 URL 的链接。当用户单击该链接时,我需要进行 API 调用和其他一些操作。

现在单击左键以及 Ctrl + 单击可以很好地触发该方法。只有在用鼠标中键打开链接时,该方法才不会被触发。

<a [href]="'somelink.com' + someVariable" target="_blank" (click)="someMethod('some', 'params')">
    <div class="some-icon">
        <img src="/assets/icon/icon.svg" height="54" alt="Icon" />
    </div>
</a>
Run Code Online (Sandbox Code Playgroud)

有没有另一种方法可以在我的组件中单击鼠标中键调用方法?

html typescript angular

5
推荐指数
1
解决办法
3902
查看次数

无法绑定到':xlink:href',因为它不是':svg:image'的已知属性

我试图像这样动态设置svg图像的href:

<svg style="width:100%; height:100%">
    <image x="-29" y="7" height="53" width="170" xlink:href="{{logoFile}}"  />
</svg>
Run Code Online (Sandbox Code Playgroud)

但是然后我在控制台中出错:无法绑定到':xlink:href',因为它不是':svg:image的已知属性

svg angular

4
推荐指数
1
解决办法
923
查看次数

根据 Angular 6 中的变量更改更改 html5 类?

如何html根据模型中变量分配的值在元素中添加/删除类。例如,value我的 Angular 组件中有一个变量:

export class SomeComponent implements OnInit {
    value: number = 6;
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在,根据值(通过事件监听器经常更新),我想在html条件为真时在元素中添加/删除一个类:

<div [ngClass]="value >= 3 ? 'bordered-section' : ''"></div>

<div [ngClass]="value >= 6 ? 'bordered-section' : ''"></div>
Run Code Online (Sandbox Code Playgroud)

我想我设法在初始化时完成这项工作,但是当变量再次更改时,类不会被删除。我该如何解决这个问题?

angular

4
推荐指数
1
解决办法
7620
查看次数

如何在 Angular 7 的表中添加行组件?

我使用最新版本的angluar。(7.2.0) 我有个人 tr 组件,如:

import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'app-table-row',
templateUrl: './table-row.component.html',
styleUrls: ['./table-row.component.scss']
})
export class TableRowComponent implements OnInit {
@Input() character: any;
@Input() columns: string[];

constructor() { }

ngOnInit() {
}

}
Run Code Online (Sandbox Code Playgroud)

我想在表中使用这个组件,如:

<table class="mat-elevation-z8">
<tr>
   <th *ngFor="let c of columns">{{c}}</th>
</tr>
<tr app-table-row class="component-style table-row-component" *ngFor="let ch of characters | async" 
   [character]="ch" 
  [columns]="columns">
</tr>

</table>
Run Code Online (Sandbox Code Playgroud)

得到如下错误:

Can't bind to 'character' since it isn't a known property of 'tr'. ("table-row class="component-style table-row-component" *ngFor="let …
Run Code Online (Sandbox Code Playgroud)

javascript components angular

4
推荐指数
1
解决办法
3567
查看次数

如何在 ngFor 循环 [Angular] 中制作可扩展的表格行?

我嵌套了表格,当单击一行时,我需要在表格行下方显示数据。但是,数据显示在 ngRepeat 的末尾。

HTML:

  <table class="table table-hover table-bordered table-responsive-xl">
  <thead>
    <th> Name </th>
    <th> Place </th>
    <th> Phone </th>
  </thead>

  <tbody>

  <tr *ngFor="let data of data1" (click) ="expand()">
        <td> +{{data.name}} </td>
        <td> {{data.place}} </td>
        <td> {{data.phone}} </td>
  <td> {{data.hobbies}} </td>
  <td> {{data.profession}} </td>
 </tr>

 <ng-container *ngIf="expandContent">
    <tr *ngFor="let data of data2">
        <td> {{data.datades.name}} </td>
        <td> {{data.datades.hobbies}} </td>
        <td> {{data.datades.profession}} </td>
 </tr>
 </ng-container>
 </tbody>
 </table>
Run Code Online (Sandbox Code Playgroud)

成分 :

export class AppComponent  {
expandContent = true;
  data1 =[{
 'name' : 'john',
 'place' : …
Run Code Online (Sandbox Code Playgroud)

html javascript twitter-bootstrap angular

4
推荐指数
1
解决办法
8376
查看次数