Я пытаюсь проверить номер GridView
, используя его onRowCommand
.
Когда я выбираю кнопку, ей необходимо проверить эти строки delivery date
и отображать сообщение об ошибке inline, если оно недействительно.Gridview On Row Command
В настоящее время мой GridView
настроен так:
<asp:GridView ID="gvDistribution" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="1000px" DataKeyNames="id" AllowPaging="True" OnPageIndexChanging="gvDistribution_PageIndexChanging" PageSize="5" OnRowCommand="gvDistribution_OnRowCommand" OnRowDataBound="gvDistribution_RowDataBound">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="name" HeaderText="Beneficiary Name"></asp:BoundField>
<asp:BoundField DataField="packingDate" HeaderText="Packing Date" DataFormatString="{0:dd/M/yyyy}"></asp:BoundField>
<asp:BoundField DataField="deliveryDate" HeaderText="Delivery Date" DataFormatString="{0:dd/M/yyyy}" />
<asp:TemplateField HeaderText="Status" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="View" Text="View Details" />
<asp:ButtonField CommandName="Action" Text="Action" />
<asp:TemplateField HeaderText="" ItemStyle-Width="120px">
<ItemTemplate>
<asp:Label ID="lblError" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
И код позади для GridView
onRowCommand
:
protected void gvDistribution_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int rowNo = int.Parse(e.CommandArgument.ToString());
string distributionID = this.gvDistribution.DataKeys[rowNo].Value.ToString();
if (e.CommandName == "View")
{
Response.Redirect("PackingDetails.aspx?id=" + distributionID);
}
else if(e.CommandName == "Action")
{
DistributionPacking distPack = new DistributionPacking();
distPack = packBLL.getDateDetailByDistributionID(distributionID);
DateTime deliveryDate = distPack.deliveryDate;
foreach (GridViewRow g in gvDistribution.Rows)
{
if (deliveryDate > DateTime.Today)
{
Label lblError = (Label)g.FindControl("lblError");
lblError.Text = "Delivery date has not reach yet!";
}
else
{
bool result = packBLL.updateDeliveryStatus(distributionID);
if (!result)
{
//Call the retrieve all distributions without any filtering again
List<DistributionPacking> allDistribution = new List<DistributionPacking>();
allDistribution = packBLL.getAllDistribution();
gvDistribution.DataSource = allDistribution;
gvDistribution.DataBind();
}
}
}
}
}
в том, что, когда delivery date
получает подтверждено, отображается вопрос сообщение об ошибке в каждый ряд, а не только тот, который нуждается в проверке.
Может ли кто-нибудь показать мне, как заставить только одно сообщение в проверенной строке?
Я установленный с помощью кода в редактируемой части. Ваша работа тоже. Большое спасибо –