网格视图。如何在空字段中显示当前值?

时间:2012-11-12 03:07:40

标签: c# asp.net gridview

我有GridView,其中填充了适配器:

OracleDataAdapter adapter = new OracleDataAdapter();
DataTable tableD = new DataTable();
adapter.SelectCommand = oracleCom;
adapter.Fill(tableD);
tableResults.DataSource = tableD.AsDataView();
tableResults.DataBind();

tableResults - 它是一个GridView。 我添加了在GridView中更改数据的功能:

tableResults.AutoGenerateEditButton = true;
tableResults.RowEditing += new GridViewEditEventHandler(tableResults_RowEditing);
tableResults.RowUpdating += new GridViewUpdateEventHandler(tableResults_RowUpdating);
tableResults.RowCancelingEdit += new GridViewCancelEditEventHandler(tableResults_RowCancelingEdit);

现在,从这个: enter image description here

当用户按下编辑链接时,他会看到: enter image description here

如何在空白字段中显示当前值?

它的补充:

<asp:GridView ID="tableResults" runat="server" DataMember="Table"
                EnableModelValidation="True" CssClass = "GridViewStyle" 
                OnRowDeleting = "dataViewRowDeleting" AutoGenerateDeleteButton="True">
               <HeaderStyle CssClass = "GridViewHeaderStyle" />
               <RowStyle CssClass = "GridViewRowStyle"/>    
               <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink runat="server" Text="Скачать объект" NavigateUrl='<%#"objects/" + Eval("Идентификатор") %>'></asp:HyperLink>
                    </ItemTemplate>    
                </asp:TemplateField>
               </Columns>           
            </asp:GridView>

1 个答案:

答案 0 :(得分:2)

您只需点击编辑,但您还必须重新绑定您的视图 只需在gridview RowEditing事件上再次绑定gridview ....

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;
    bindGridView1();
}
试试这个,这肯定会帮到你。如果你仍然遇到任何问题而不是在这里描述你的问题......