viewproducts 페이지가 있는데 편집 링크를 클릭하면 두 필드가 편집됩니다 (이름 및 가격). 뒤에boundfield의 데이터를 업데이트하는 중 (입력 문자열의 형식이 올바르지 않습니다.)
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Text="Edit" runat="server" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton2" Text="Update" runat="server" OnClick="OnUpdate" />
<asp:LinkButton ID="LinkButton3" Text="Cancel" runat="server" OnClick="OnCancel" />
</EditItemTemplate>
</asp:TemplateField>
및 코드 : : 입력 문자열이 올바른 형식이 아니었다 : 그것은 나에게 말하는 오류를 제공하지만
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart()
{
CategoryID = CategoryID
};
gdview.DataSource = null;
gdview.DataSource = k.GetAllProducts();
gdview.DataBind();
}
protected void OnRowEditing(object sender, GridViewEditEventArgs e)
{
gdview.EditIndex = e.NewEditIndex;
this.GetProducts(0);
}
protected void OnUpdate(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string Name = (row.Cells[0].Controls[0] as TextBox).Text;
string Price = (row.Cells[2].Controls[0] as TextBox).Text;
DataTable dt = ViewState["dt"] as DataTable;
dt.Rows[row.RowIndex]["Name"] = Name;
dt.Rows[row.RowIndex]["Price"] = Price;
ViewState["dt"] = dt;
gdview.EditIndex = -1;
this.GetProducts(0);
}
protected void OnCancel(object sender, EventArgs e)
{
gdview.EditIndex = -1;
this.GetProducts(0);
}
protected void gdview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToInt32(e.Row.Cells[6].Text) < 50)
{
e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
e.Row.Cells[0].ForeColor = System.Drawing.Color.White;
e.Row.Cells[6].BackColor = System.Drawing.Color.Red;
e.Row.Cells[6].ForeColor = System.Drawing.Color.White;
}
}
}
여기 내 html 코드이다. 빨간색 텍스트는 다음과 함께 표시됩니다.
if (Convert.ToInt32(e.Row.Cells[6].Text) < 50)
무엇이 여기에 있습니까? 편집을위한 텍스트 상자가 표시 될 때
<Columns>
<asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="ProductCategory " ReadOnly="true" DataField="CategoryName" SortExpression="CategoryNaame" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="Price" DataField="Price" SortExpression="Price" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:ImageField HeaderText ="ImageUrl" DataImageUrlField="ImageUrl" SortExpression="ImageUrl" ReadOnly="true" ControlStyle-Width ="10">
<ControlStyle Width="50px"></ControlStyle>
</asp:ImageField>
<asp:BoundField HeaderText="ProductQuantity" DataField="ProductQuantity" ReadOnly="true" SortExpression="ProductQuantity" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="ProductSold" DataField="ProductSold" SortExpression="ProductSold" ReadOnly="true" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
<asp:BoundField HeaderText="AvailableStock" DataField="AvailableStock" SortExpression="AvailableStock " ReadOnly="true" >
<ItemStyle Height="20px" Width="150px" />
</asp:BoundField>
이름 필드는 사라 : 여기
이있는 gridview 코드?
에서 t? – Mairaj
@MairajAhmad 가능한 재고입니다. int. 20 미만이되면 붉은 색으로 변합니다. –
오류가 발생했을 때 비어 있어야합니다. 'if (! string.IsNullOrEmpty (e.Row.Cells [6] .Text))' – Mairaj