있는 gridview의 코드 :GRIDVIEW의 onrowupdating는 새 값
<asp:GridView ID="uxItemsGV" runat="server" AllowPaging="True" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="20"
AutoGenerateColumns="False" OnRowEditing="uxItemsGV_RowEditing"
onpageindexchanging="uxItemsGV_PageIndexChanging"
onpageindexchanged="uxItemsGV_PageIndexChanged" AutoGenerateEditButton="True"
onrowupdated="uxItemsGV_RowUpdated" onrowupdating="uxItemsGV_RowUpdating"
onrowcancelingedit="uxItemsGV_RowCancelingEdit">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="ItemID" HeaderText="Item ID" ReadOnly="true" />
<asp:BoundField DataField="ItemName" HeaderText="Title" />
<asp:BoundField DataField="QuantityOnHand" HeaderText="Quantity" />
<asp:BoundField DataField="Totalsold" HeaderText="Total Sold" />
<asp:BoundField DataField="RetailPrice" HeaderText="SR Price" />
<asp:BoundField DataField="Dateofadd" HeaderText="Added Date" ReadOnly="true" />
</Columns>
<PagerSettings Position="TopAndBottom" FirstPageText="First"
LastPageText="Last" Mode="NextPreviousFirstLast" NextPageText=">>"
PreviousPageText="<<" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
뒤에 코드 : 나는 업데이트 링크를 클릭하면
protected void uxItemsGV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = uxItemsGV.Rows[e.RowIndex];
try
{
BVController.Updateitem(int.Parse(row.Cells[1].Text), Session["CategoryID"].ToString(), ((TextBox)row.Cells[2].Controls[0]).Text.Trim(),
int.Parse(((TextBox)row.Cells[3].Controls[0]).Text.Trim()), decimal.Parse(((TextBox)row.Cells[5].Controls[0]).Text.Trim()),
int.Parse(((TextBox)row.Cells[4].Controls[0]).Text.Trim()));
uxUserMessage.Text = "Item " + row.Cells[1].Text + " has been updated.";
}
catch (Exception ex)
{
uxUserMessage.Text = "The following error occured: " + ex.Message;
MsgBlock.Visible = true;
}
}
코드는 업데이트가 이루어 말했지만 변화가 없었다 만든. 중단 점을 설정하고 코드가 이전 값을 전달하여 업데이트를 커밋한다는 것을 알았습니다. 어떤 새로운 가치도 받아 들여지지 않습니다. 어떠한 제안? 감사!
그리드에 편집 컨트롤이 없기 때문에 정보를 변경할 수있는 곳이 없습니다. –
gridview 태그에 "AutoGenerateEditButton ="True ""를 추가했습니다. 자동으로 Gridview에 편집 열을 추가합니다. – abear2011
편집 단추가 표시되었다고해서 필드를 편집 할 수있는 것은 아닙니다. 수정 버튼을 클릭하면 편집 가능한 입력란이 보이나요? –