下面的gridview中,获取某行某列的值(非模板页),如图所示

gridview中后台获取某列的值-LMLPHP

   <asp:GridView AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover" ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
<asp:TextBox ID="hidPercent" runat="server" Text='<%#GetPercent(Eval("name").ToString(),Eval("StuCount").ToString(),Eval("ContractName").ToString(),1) %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" HeaderText="代理名称" ReadOnly="true" />
<asp:BoundField DataField="ContractName" HeaderText="合同名称" ReadOnly="true" />
<asp:HyperLinkField DataNavigateUrlFields="name,ContractName,ReturnCommissionCurrency,IsState" DataNavigateUrlFormatString="AgentStuDetailSP.aspx?a=1&aName={0}&cName={1}&ucc={2}&isstate={3}" HeaderText="签约人数" DataTextField="StuCount" />
<asp:TemplateField HeaderText="签约总人数">
<ItemTemplate>
<a href='<%#"AgentStuDetailSP.aspx?a=2&aName="+Eval("name")+"&cName"+Eval("ContractName")+"&ucc="+Eval("ReturnCommissionCurrency")+"&isstate="+ Eval("IsState") %>'>
<%#GetPercent(Eval("name").ToString(),Eval("StuCount").ToString(),Eval("ContractName").ToString(),) %></a>
</ItemTemplate> </asp:TemplateField>
<asp:BoundField DataField="ReturnCommissionCurrency" HeaderText="币种" ReadOnly="true" />
<asp:BoundField DataField="sumMoney" HeaderText="返佣总额" ReadOnly="true" />
<asp:TemplateField HeaderText="返佣百分比">
<ItemTemplate>
<%#GetPercent(Eval("name").ToString(),Eval("StuCount").ToString(),Eval("ContractName").ToString(),) %>%
</ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="应返代理金额">
<ItemTemplate>
<%#(GetPercent(Eval("name").ToString(),Eval("StuCount").ToString(),Eval("ContractName").ToString(),)/ *decimal.Parse( Eval("sumMoney").ToString()==null?"":Eval("sumMoney").ToString() ))%>
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="返佣状态">
<ItemTemplate>
<%#GetIsState(Eval("IsState").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

选择所需的列,点击更新状态。。更改选中列状态,后台方法为

   protected void btnUpdate_Click(object sender, EventArgs e)
{
// 遍历GridView中的每一行
for (int i = ; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
string temp = GridView1.Rows[i].Cells[].Text;
if (cbox.Checked == true)
{
// 获行当前行
GridViewRow gridRow = GridView1.Rows[i];
// 通过DATAKEYS来取行没显示出来的ID号
string agentName = GridView1.DataKeys[i].Value.ToString();
string conName = gridRow.Cells[].Text.Trim();
if (conName == "&nbsp;")
{
conName = "";
}
string ReturnCC = gridRow.Cells[].Text.Trim();//获取到的选中列的对应行的值
string isState = gridRow.Cells[].Text.Trim();
//GetDataS(1, agentName, conName, ReturnCC, isState, "");
}
}
GetData();
}
04-30 19:04