我创建了一个 gridview 它有最喜欢的按钮,当我点击它时我想更改它的 url。我该怎么做?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Width="446px" AllowPaging="True"
onrowcommand="GridView1_RowCommand1"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:ImageField AlternateText="Add To Favorites" Visible=false
DataImageUrlFormatString=""~/images/favorites.png""
FooterText="Add To Favorites" HeaderText="Add To Favorites">
<FooterStyle Width="10px" />
</asp:ImageField>
<asp:ButtonField CommandName="AddComment" ButtonType="Image" HeaderText="Comment" ImageUrl="~/images/commentt.png" Text="Comment" ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField CommandName="Share" ButtonType="Image" HeaderText="Share with Friends" ImageUrl="~/images/openshare.png" ItemStyle-HorizontalAlign="Center" Text="Share" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField CommandName="ShareGroups" ButtonType="Image" HeaderText="Share with Groups" ImageUrl="~/images/openshare.png" ItemStyle-HorizontalAlign="Center" Text="Share" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField ButtonType="Image" HeaderText="Favorites"
ImageUrl="~/images/StarEmpty.png" CommandName="Favorite"
Text="Add to Favorites" ItemStyle-HorizontalAlign="Center">
<FooterStyle Height="20px" />
<HeaderStyle Width="3px" />
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField ButtonType="Image" CommandName="Mail" HeaderText="Send Mail"
ImageUrl="~/images/email-icon.png.jpg" Text="Send Mail"
ItemStyle-HorizontalAlign="Center" InsertVisible="False" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonField>
<asp:ButtonField CommandName="View" Text="View Rss"
HeaderText="View Rss" ItemStyle-HorizontalAlign="Center" >
<HeaderStyle Width="50px" />
<ItemStyle Width="15px" />
</asp:ButtonField>
<asp:BoundField DataField="RSS_Title" HeaderText="RSS_Title"
SortExpression="RSS_Title" />
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%#Eval("RSS_ID")%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我的 C# 代码如下
if (e.CommandName == "Favorite")
{
//GridView1.Rows[rowIndex].Cells[2].
string sValue = ((HiddenField)GridView1.Rows[rowIndex].FindControl("HiddenField1")).Value;
int id = Convert.ToInt32(sValue);
Session["SelectedRSS"] = sValue;
DBConnection db = new DBConnection();
bool res = db.CheckFavorites(id, User_Name);
// if favorite rss doesnot exist
if (!res)
{
Boolean result = db.addFavorite(id, User_Name);
DataSet selectedRSS = db.getRSS(id);
DataTable dt = selectedRSS.Tables[0];
DataRow row = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
row = dt.Rows[i];
countOfFavorite = Convert.ToInt32(row[3].ToString());
}
countOfFavorite++;
Boolean result1 = db.increaseFavoriteCount(id, countOfFavorite);
// rssi favori olarak user dosyasına kaydet;
}
}