我希望从每个记录的网格视图中获取当前的鼠标,并将其保存在我的数据库中。 但我不能像网格视图中的其他控件那样调用它。如何在网格视图中保存每行的费率? 这是我的数据库表中记录的ID:
int idx = Convert.ToInt32(e.CommandArgument);
idx = idx - (GridView2.PageSize * GridView2.PageIndex);
int ID = (int)GridView2.DataKeys[idx].Value;
我每行需要这个:
int rating = rating2.CurrentRating;
gridview的Html cod:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1" Font-Names="Tahoma"
Font-Size="9pt" style="margin-left: 0px" Width="799px" GridLines="None">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div style="width: 950px">
<table align="center" style="width: 100%;">
<tr>
<td align="center" colspan="3">
<div class="box1">
<div class="box-t">
<div class="b-l">
</div>
<div class="b-bg" dir="rtl">
<asp:Label ID="Label6" runat="server" Font-Names="Tahoma"
Text='<%# Eval("Title") %>'></asp:Label>
</div>
<div class="b-r">
</div>
</div>
<div class="box-bg">
<div class="content">
<table style="width: 100%; height: 8px;">
<tr>
<td align="right">
<div style="padding: 15px">
<asp:Label ID="Label10" runat="server" Font-Names="Tahoma" ForeColor="Black"
Text='<%# Eval("Body") %>'></asp:Label>
</div>
<br />
</td>
</tr>
<tr>
<td align="right">
<br />
<asp:Rating ID="Rating2" runat="server" CurrentRating="1" MaxRating="6" StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" style="float: right;" />
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="btnSubmit" runat="server"
CommandArgument="<%# Container.DataItemIndex %>" Font-Names="Tahoma"
Font-Size="9pt" oncommand="SubmitRating" Text="به این مطلب امتیاز دهید" />
</td>
</tr>
</table>
</div>
</div>
<div class="box-b">
<asp:Label ID="Label8" runat="server" Font-Italic="False" Font-Names="Homa"
Text=" تاریخ بارگذاری :"></asp:Label>
<asp:Label ID="Label11" runat="server" Font-Names="Homa"
Text='<%# JulianToPersianDate((DateTime)Eval("Date")) %>'></asp:Label>
</div>
</div>
</td>
</tr>
<tr>
<td align="center">
</td>
<td align="center">
</td>
<td align="center">
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
任何身体都可以帮助我吗?
答案 0 :(得分:0)
您可以循环浏览gridview
foreach(GridViewRow row in GridView2.Rows)
{
// here you'll get all rows with RowType=DataRow
// others like Header are omitted in a foreach
}
并访问所有列
foreach(GridViewRow row in GridView2.Rows)
{
for(int i = 0; i < GridView2.Columns.Count, i++)
{
//String header = GridView2.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
}
}
类似地,您可以在网格视图中使用find控件,如下所示
foreach(GridViewRow row in gv.Rows)
{
TextBox txtTotal = row.cells[0].Controls[0].FindControl("TOTAL") as TextBox;
string value = txtTotal.Text;
// Do something with the textBox's value
}
类似地,你必须在单元格中找到你Rating2
并将其转换为评级控制并获得它的价值。