0
我正在使用Gridview來處理我的結果vía複選框,並計劃在ModalPopUp中的textField中顯示它。第一件事是第一件事。我想處理它,並在某種程度上使用TemplateField時,我的警報中看不到任何結果。但是當我嘗試使用BoundField時,結果確實顯示。我不知道是否因爲我只能顯示boundField或我做錯了什麼。這是我用於這個特定部分的代碼部分。每次我用一個TemplateField它不會工作:(這裏模板字段不顯示,應該使用BoundField? (不工作)
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="selectedMail" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True"
SortExpression="Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" />
<asp:TemplateField HeaderText="Complete Name" SortExpression="FirstName">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemTemplate>
<a href='candidato.aspx?key=<%#Eval("Key")%>'>
<%# Eval("FirstName") %>
<%# Eval("MiddleName") %>
<%# Eval("LastName") %>
<%# Eval("SecondLastName") %></a>
<br />
<small><%# GetLabels(Eval("Id").ToString())%></small>
</ItemTemplate>
<FooterTemplate>
Total candidates: <asp:Label ID="lblTotalApplicants" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vacancies" SortExpression="">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
<ItemTemplate>
<%# GetVacante(Eval("email").ToString())%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Status.Nombre" HeaderText="Status"
SortExpression="Status.Nombre" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top" />
<asp:TemplateField HeaderText="Created Date" SortExpression="CreatedDate">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("createdDate", "{0:MMMM dd, yyyy. H:mm}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Top" />
<asp:TemplateField HeaderText="Email" SortExpression="" runat="server">
<ItemTemplate>
<%# Eval("email")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
asp.cs是它的後端。
public void loadEmail(object sender, EventArgs e)
{
String compEmail = "";
foreach (GridViewRow row in gvApplicants.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox selectedMail = (row.Cells[0].FindControl("selectedMail") as CheckBox);
if (selectedMail.Checked)
{
string email = row.Cells[7].Text;
compEmail = compEmail+" "+ email;
}
}
}
string url = HttpContext.Current.Request.Url.AbsoluteUri;
string script = "window.onload = function(){ alert('";
script += compEmail;
script += "');";
script += "window.location = '";
script += url;
script += "'; }";
ClientScript.RegisterStartupScript(this.GetType(), "Redirect", script, true);
}
當您使用TemplateField時發生了什麼? string email = row.Cells [7] .Text; – Seano666
完成空。警報空白。 –
TemplateField可能會生成一個容器,並且您的控件位於容器中。爲了找到答案,你需要做一些基本的調試,設置一個斷點並檢查一下row.Cells [7]找出你的控件在哪裏。 – Seano666