问题描述
protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){DataTabledt=newDataTable();DataColumndc1=newDataColumn("f_name");dc1.Caption="姓名";dt.Columns.Add(dc1);DataColumndc2=newDataColumn("f_id");dc2.Caption="编码";dt.Columns.Add(dc2);DataRowdr1=dt.NewRow();dr1["f_name"]="Helloworld";dr1["f_id"]="001";dt.Rows.Add(dr1);GridView1.DataSource=dt;GridView1.DataBind();}}//====================================================================================<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"Height="145px"Width="335px"><Columns><asp:TemplateFieldHeaderText="编码"><EditItemTemplate> </EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label><asp:LabelID="Label2"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="姓名"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label3"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
解决方案
解决方案二:
你EditItemTemplate里面是空的
解决方案三:
<EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate>这不是有内容吗,为何说是空的?请明示,小弟刚学asp.net,谢谢
解决方案四:
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"Height="145px"Width="335px"><Columns><asp:TemplateFieldHeaderText="编码"><EditItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="姓名"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label3"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
解决方案五:
gridview加上DataKeyNames=""
解决方案六:
gridview加上DataKeyNames="主键"
解决方案七:
<tablecellspacing="0"rules="all"border="1"id="GridView1"style="height:145px;width:335px;border-collapse:collapse;"><tr><thscope="col">编码</th><thscope="col">姓名</th></tr><tr><td><spanid="GridView1_ctl02_Label1">001</span><spanid="GridView1_ctl02_Label2">Helloworld</span></td><td><spanid="GridView1_ctl02_Label3">Helloworld</span></td></tr></table>TextBox根本未显示,这是为何?
解决方案八:
<asp:TemplateFieldHeaderText="编码"><EditItemTemplate> ???</EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label><asp:LabelID="Label2"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField>模板列里的文本框被你删除了?加上去,再设置要绑定的列名称。
解决方案九:
看名称里的EditItemTemplate,那个是有的
解决方案十:
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames=""OnSelectedIndexChanged="GridView1_SelectedIndexChanged"Height="145px"Width="335px"><Columns><asp:TemplateFieldHeaderText="编码"><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label><asp:LabelID="Label2"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="姓名"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label3"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
解决方案十一:
protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){DataTabledt=newDataTable();DataColumndc1=newDataColumn("f_name");dc1.Caption="姓名";dt.Columns.Add(dc1);DataColumndc2=newDataColumn("f_id");dc2.Caption="编码";dt.Columns.Add(dc2);DataRowdr1=dt.NewRow();dr1["f_name"]="Helloworld";dr1["f_id"]="001";dt.Rows.Add(dr1);GridView1.DataSource=dt;GridView1.DataBind();}}<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"Width="335px"><Columns><asp:TemplateFieldHeaderText="编码"><EditItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="姓名"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label3"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField></Columns></asp:GridView>我试过没问题
解决方案十二:
那我这咋不行,不会是我的VS出了问题吧?
解决方案十三:
工程上需要作什么特殊设置吗?
解决方案十四:
我这编辑框就是不出来,不知为何?
解决方案十五:
protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){gvDataBind();}}publicvoidgvDataBind(){DataTabledt=newDataTable();DataColumndc1=newDataColumn("f_name");dc1.Caption="姓名";dt.Columns.Add(dc1);DataColumndc2=newDataColumn("f_id");dc2.Caption="编码";dt.Columns.Add(dc2);DataRowdr1=dt.NewRow();dr1["f_name"]="Helloworld";dr1["f_id"]="001";dt.Rows.Add(dr1);GridView1.DataSource=dt;GridView1.DataBind();}protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse){GridView1.EditIndex=e.NewEditIndex;gvDataBind();}protectedvoidGridView1_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse){GridView1.EditIndex=-1;gvDataBind();}<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="f_id"OnRowEditing="GridView1_RowEditing"OnRowCancelingEdit="GridView1_RowCancelingEdit"><Columns><asp:BoundFieldDataField="f_id"Visible="false"/><asp:BoundFieldDataField="f_name"Visible="false"/><asp:TemplateFieldHeaderText="编码"><EditItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("f_id")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateFieldHeaderText="姓名"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Width="221px"Text='<%#Bind("f_name")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label3"runat="server"Text='<%#Bind("f_name")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:CommandFieldShowEditButton="true"/></Columns></asp:GridView>
解决方案:我也不知为何,我也和你相似的用法就是不懂。。过来查找资料偶然看到。。
解决方案:我也遇到同样的问题。楼主搞定了吗?