如何在ASP.NET的gridview中獲得EditTemplate控件的控件類型?如何獲取Gridview模板中的控件類型?
要獲得一個綁定的控件的類型,我只是做這個
foreach (TableCell cell in grdViewDetails.Rows[e.RowIndex].Cells)
{
//set the employeeid so you can update the dataset
if (cell.Controls[0] is CheckBox)
{
CheckBox check = (CheckBox)cell.Controls[0];
//Do stuff with the control and the text inside the control etc;
}
}
,但我不能似乎找到模板中的控件。他們只是跳過這個。
我試過無濟於事。
foreach (TableCell cell in grdViewDetails.Rows[e.RowIndex].Cells)
{
var test1 = cell.Controls[0];
columnName = dsOriginal.Tables[0].Columns[startOfColumns].ColumnName; //[System.Web.UI.LiteralControl] I can find the Column Name but it't not a normal control... It's a LiteralControl?
var test2 = cell.FindControl("CheckWeek2"); //[System.Web.UI.WebControls.Calendar] = {SelectedDate = The name 'SelectedData' does not exist in the current context}
}
我的GridView控件模板
<asp:TemplateField HeaderText="week2" SortExpression="week2">
<EditItemTemplate>
<asp:CheckBox ID="CheckWeek2" runat="server" Checked='<%# Bind("week2") %>'></asp:CheckBox>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="Label2" runat="server" Enabled="false" Checked='<%# Bind("week2") %>'></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
哪個事件你試圖找到編輯模板控件? – Damith 2013-04-29 07:50:14
我想獲取正在編輯的控件的文本/缺陷。 – Ruan 2013-04-29 07:52:16