我的网格视图中有三列名为TweetText,TweetImageUrl和一列ImageFied 其DataImageUrl字段是TweetImageURl。我的问题是,当我使用网格的编辑,更新功能时,我无法编辑/更新TweetImageUrl,但我可以更新TweetText。但是当我删除ImageField列时,我也可以更新TweetImageUrl列。那么任何人都可以提供帮助,以便我可以在Grid Too中使用ImageField更新TweetImageUrl吗?
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="TwitterUserId"
DataSourceID="SqlDataSource1" onrowcommand="GridView1_RowCommand"
PageSize="14" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Approve" runat="server"
CommandName="Approve"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Approve" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TweetText" HeaderText="TweetText"
SortExpression="TweetText" />
<asp:BoundField DataField="TweetImageUrl" HeaderText="TweetImageUrl"
SortExpression="TweetImageUrl" />
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px"
NullImageUrl="~/Admin/ajax-loader.gif">
</asp:ImageField>
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:mistersmartyplantsConnectionString %>"
DeleteCommand="DELETE FROM [TwitterData] WHERE [TwitterUserId] = @original_TwitterUserId AND (([TweetId] = @original_TweetId) OR ([TweetId] IS NULL AND @original_TweetId IS NULL)) AND (([TwitterUserName] = @original_TwitterUserName) OR ([TwitterUserName] IS NULL AND @original_TwitterUserName IS NULL)) AND (([TweetText] = @original_TweetText) OR ([TweetText] IS NULL AND @original_TweetText IS NULL)) AND (([TweetImageUrl] = @original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND @original_TweetImageUrl IS NULL)) AND (([TwitterDate] = @original_TwitterDate) OR ([TwitterDate] IS NULL AND @original_TwitterDate IS NULL))"
InsertCommand="INSERT INTO [TwitterData] ([TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate]) VALUES (@TweetId, @TwitterUserId, @TwitterUserName, @TweetText, @TweetImageUrl, @TwitterDate)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [TweetId], [TwitterUserId], [TwitterUserName], [TweetText], [TweetImageUrl], [TwitterDate] FROM [TwitterData] WHERE ([Approved] = @Approved) ORDER BY [TwitterDate] DESC"
UpdateCommand="UPDATE [TwitterData] SET [TweetId] = @TweetId, [TwitterUserName] = @TwitterUserName, [TweetText] = @TweetText, [TweetImageUrl] = @TweetImageUrl, [TwitterDate] = @TwitterDate WHERE [TwitterUserId] = @original_TwitterUserId AND (([TweetId] = @original_TweetId) OR ([TweetId] IS NULL AND @original_TweetId IS NULL)) AND (([TwitterUserName] = @original_TwitterUserName) OR ([TwitterUserName] IS NULL AND @original_TwitterUserName IS NULL)) AND (([TweetText] = @original_TweetText) OR ([TweetText] IS NULL AND @original_TweetText IS NULL)) AND (([TweetImageUrl] = @original_TweetImageUrl) OR ([TweetImageUrl] IS NULL AND @original_TweetImageUrl IS NULL)) AND (([TwitterDate] = @original_TwitterDate) OR ([TwitterDate] IS NULL AND @original_TwitterDate IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter DefaultValue="No" Name="Approved" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="TweetId" Type="String" />
<asp:Parameter Name="TwitterUserName" Type="String" />
<asp:Parameter Name="TweetText" Type="String" />
<asp:Parameter Name="TweetImageUrl" Type="String" />
<asp:Parameter Name="TwitterDate" Type="String" />
<asp:Parameter Name="original_TwitterUserId" Type="String" />
<asp:Parameter Name="original_TweetId" Type="String" />
<asp:Parameter Name="original_TwitterUserName" Type="String" />
<asp:Parameter Name="original_TweetText" Type="String" />
<asp:Parameter Name="original_TweetImageUrl" Type="String" />
<asp:Parameter Name="original_TwitterDate" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
使用
<asp:TemplateField HeaderText="Images" ItemStyle-Height="10px" ItemStyle-Width="10px" >
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval(TweetImageUrl) %>' Height="10px" Width="10px" />
</ItemTemplate>
</asp:TemplateField>
而不是
<asp:ImageField DataImageUrlField="TweetImageUrl" HeaderText="Images" ItemStyle-Height = "10px" ItemStyle-Width = "10px" NullImageUrl="~/Admin/ajax-loader.gif"></asp:ImageField>
希望它有所帮助。祝你好运。