Okay, I have a Gridview control that I use to edit records in my database. I have parameterized the query also. Here's the code:
<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>
Not sure if it has to do with the TemplateField control or the Parameter type being a string. The reason I mention the Type property is because in my Access database, they are of the memo type, but the only thing I can see that is halfway comparable is the string type. I'd wager that the string type isn't big enough to hold a memo field, but I don't know what else might be going on. Any help would be greatly appreciated.
There's nothing wrong with memo field. Its the edititemtemplatefields, you are not binding data. Change Eval
to Bind
, for example, change this:
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Eval("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
to this:
<EditItemTemplate>
<asp:TextBox id="PicTextBox" runat="server" text='<%# Bind("PicText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
Change this :
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Eval("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
to this:
<EditItemTemplate>
<asp:TextBox id="BeginTextBox" runat="server" text='<%# Bind("BeginText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
And change this:
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Eval("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
to this:
<EditItemTemplate>
<asp:TextBox id="EndTextBox" runat="server" text='<%# Bind("EndText")%>' textmode="MultiLine" height="300px" width="300px" />
</EditItemTemplate>
I have tested it with access db. Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With