我需要将每行每个单元格的gridview值作为变量,使用webusercontrol在asp.net中的webform上显示 我试过这个,但它没有用,
Control control1 = null;
GridView GridView1 = (GridView)this.FindControl("GridView");
foreach (GridViewRow row1 in GridView1.Rows)
{
control1 = GridView1.Controls[0].Controls[0];
string Price = (control1.FindControl("Price") as Label).Text;
string Quantity = (control1.FindControl("Quantity") as Label).Text;
}
答案 0 :(得分:1)
您已经循环了所有GridViewRows
,这些是NamingContainers
中ItemTemplate
标签的row.FindControl
控件,您可以使用foreach (GridViewRow row in GridView1.Rows)
{
Label lblPrice = (Label)row.FindControl("Price");
string Price = lblPrice.Text;
Label lblQuantity = (Label)row.FindControl("Quantity");
string Quantity = lblQuantity.Text;
}
找到这些控件:
validator.Validate(client, ruleSet: "Production");
public class ClientValidator : AbstractValidator<Client>
{
public ClientValidator()
{
RuleSet("Production", () =>
{
RuleFor(client => client.Orders)
.SetCollectionValidator(new OrderValidator());
When(client => client.IsVIP, () => {
RuleFor(client => client.Orders)
.SetCollectionValidator(new OrderValidator());
//.SetCollectionValidator(new OrderValidator("VIPClient"));
});
});
}
}
public class OrderValidator : AbstractValidator<Order>
{
public OrderValidator()
{
RuleSet("Production", () =>
{
RuleFor(x => x.Items)
.NotEmpty();
});
RuleSet("VIPClient", () =>
{
RuleFor(x => x.Discount)
.GreaterThan(0);
});
}
}