好的,我有一个Gridview控件,用于编辑数据库中的记录。我也参数化了查询。这是代码:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
DataSourceID="AccessDataSource1"
AutoGenerateColumns="False" DataKeyNames="ID"
AlternatingRowStyle-BackColor="Gray"
AlternatingRowStyle-CssClass="editGridFormat" RowStyle-CssClass="editGridFormat"
RowStyle-VerticalAlign="Top"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="BlogTitle" HeaderText="BlogTitle"
SortExpression="BlogTitle" />
<asp:ImageField DataImageUrlField="Image" HeaderText="Image"
DataImageUrlFormatString="~/PlaceImages/{0}" ControlStyle-CssClass="editPhotoGridFormat"
AlternateText="Something went wrong"
NullDisplayText="No picture on file" />
<asp:TemplateField headertext="PicText">
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Eval("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("PicText")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TravelDate" HeaderText="TravelDate" SortExpression="TravelDate" />
<asp:TemplateField headertext="BeginText">
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Eval("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("BeginText")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Caption" HeaderText="Caption" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:TemplateField headertext="EndText">
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Eval("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
<ItemTemplate>
<%# Eval("EndText")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/TravelJoansDB.mdb"
SelectCommand="SELECT * FROM [Table2]"
DeleteCommand="DELETE FROM Table2 WHERE [ID] = ?"
UpdateCommand="UPDATE Table2 SET [BlogTitle] = ?,
[Image] = ?,
[PicText] = ?,
[TravelDate] = ?,
[BeginText] = ?,
[Caption] = ?,
[City] = ?,
[Country] = ?,
[EndText] = ?
WHERE [ID] = ? " >
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="BlogTitle" Type="String" />
<asp:Parameter Name="Image" Type="String" />
<asp:Parameter Name="PicText" Type="String" />
<asp:Parameter Name="TravelDate" DbType="Date" />
<asp:Parameter Name="BeginText" Type="String" />
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="EndText" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
不确定它是否与TemplateField控件或参数类型是字符串有关。我提到Type属性的原因是因为在我的Access数据库中,它们是备忘录类型,但我能看到的唯一可比的是字符串类型。我打赌,字符串类型不足以容纳备忘录字段,但我不知道还有什么可能发生。任何帮助将不胜感激。
答案 0 :(得分:6)
备忘录字段没有错。它是edititemtemplatefields,你不是绑定数据。例如,将Eval
更改为Bind
,请更改此项:
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Eval("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
到此:
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Bind("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
改变这个:
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Eval("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
到此:
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Bind("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
并改变这一点:
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Eval("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
到此:
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Bind("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
我已经使用access db测试了它。希望它有所帮助!