Edititemtemplate未显示

时间:2014-05-28 11:48:20

标签: c# asp.net gridview

我正在尝试在gridview中显示可编辑的文本框,但文本框不可见。

谢谢大家的回答。

但问题仍然存在,

编辑代码:

<asp:GridView ID="ele_display_grid" runat="server" CssClass="stream_elements_grid" AutoGenerateColumns="false" AutoGenerateEditButton="true" OnRowEditing="ele_display_grid_RowEditing" OnRowUpdating="ele_display_grid_RowUpdating">
 <Columns>
                    <asp:TemplateField HeaderText ="Element Name">
                        <ItemTemplate>
                            <asp:Label ID="new_grid_ele" runat="server" Text='<%# Eval("element_name") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Composition">
                        <ItemTemplate>
                            <asp:Label ID="new_grid_compo" runat="server" Text='<%# Eval("composition") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>

            </asp:GridView>

在代码背后:

protected void get_selected_vals_Click(object sender, EventArgs e)
    {
        BindGrid();
    }

 private void BindGrid()
    {
        List<ListItem> selected = new List<ListItem>();
        foreach (ListItem item in ajaxElementsCheckbox.Items)
            if (item.Selected) selected.Add(item);

        for (int i = 0; i < selected.Count; i++)
        {
            string name = selected[i].ToString();
            double compo = 1;

            stream_list my_str = new stream_list(name, compo);
            elenamescompolist.Add(my_str);

        }//end of outer for.

        ele_display_grid.DataSource = elenamescompolist;
        ele_display_grid.DataBind();
    }

  protected void ele_display_grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Debug.WriteLine("On row Editing.......");
    }

    protected void ele_display_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Debug.WriteLine("On row updating.......");
    }

我正在编辑链接,但我无法点击它..

EDITTING:

它被解决了......我正在将gridview放在图像上,问题在于z-index。我将背景图像的z-index更改为0并且一切正常...感谢大家的答案..

1 个答案:

答案 0 :(得分:0)

指定要在编辑模式下显示的TextBox。除非您的gridview编辑索引等于特定行索引,否则不会显示它。

查看GridView.EditIndex的详细信息。

通常可以在GridView标记中添加asp:CommandField

<asp:CommandField ButtonType="Button" 
                  HeaderText="Edit/Update" 
                  ShowEditButton="True"
                  ShowHeader="True">                                
</asp:CommandField>

您需要跟踪这些事件

OnRowEditing  //for settings GridView.EditIndex to GridViewRow Index
OnRowCancelingEdit //for setting GridView.EditIndex back to -1
OnRowUpdating //for updating record and setting GridView.EditIndex back to -1

<强>更新

首先将数据源绑定保存到单独的方法中:

protected void get_selected_vals_Click(object sender, EventArgs e)
{       
       BindGrid();
}

private void BindGrid()
{
    List<ListItem> selected = new List<ListItem>();
    foreach (ListItem item in ajaxElementsCheckbox.Items)
        if (item.Selected) selected.Add(item);

    for(int i=0; i<selected.Count; i++)
    {            
        string name = selected[i].ToString();
        double compo = 1;

        stream_list my_str = new stream_list(name, compo);
        elenamescompolist.Add(my_str);


    }//end of outer for.

   ele_display_grid.DataSource = elenamescompolist;
   ele_display_grid.DataBind();
}

GridView的行编辑事件

 protected void ele_display_grid_RowEditing(object sender, GridViewEditEventArgs e)
    {            
        ele_display_grid.EditIndex = e.NewEditIndex;
        BindGrid();
    }

GridView的行更新事件

 protected void ele_display_grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Update datasource here

        ele_display_grid.EditIndex = -1;
        BindGrid();
    }

行取消GridView的编辑事件

protected void ele_display_grid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        ele_display_grid.EditIndex = -1;
        BindGrid();
    }