0
我有一個DetailsView控件沒有附加到數據源,但是被存儲過程填充。另外,我沒有在標記中定義任何字段。我遇到的問題是在ItemUpdating事件期間抓取單元格文本。例如,我想從五行中的每一行的單元格1中獲取文本並將它們存儲到變量中,但每次變量的文本都會返回空值。任何幫助,將不勝感激。下面是我的標記,然後是代碼隱藏:從DetailsView獲取單元格文本
<asp:DetailsView ID="goalsDetailsView" runat="server" AllowPaging="True"
CssClass="mGrid" DataKeyNames="GoalID,TaskSetID" Height="50px"
onitemcreated="goalsDetailsView_ItemCreated"
onmodechanging="goalsDetailsView_ModeChanging"
OnPageIndexChanging="goalsDetailsView_PageIndexChanging" Width="100%"
onitemdeleting="goalsDetailsView_ItemDeleting"
onitemupdating="goalsDetailsView_ItemUpdating">
<Fields>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
</Fields>
</asp:DetailsView>
protected void goalsDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
//Accessing Edited values from the Details View
//grab the goalid and create a string guid
string strgoalid = goalsDetailsView.Rows[0].Cells[1].Text; //GoalID
Guid goalid = new Guid(strgoalid);
//grab the tasksetid and create a string guid
string strtasksetid = goalsDetailsView.Rows[1].Cells[1].Text; //TaskSetID
Guid tasksetid = new Guid(strtasksetid);
//grab goal text
//string goal = ((TextBox)GoalsGridView.Rows[3].Cells[1].Controls[0]).Text; //Company
string goal = goalsDetailsView.Rows[2].Cells[1].Text;
//grab task text
string Task1 = goalsDetailsView.Rows[3].Cells[1].Text; //Task 1
string Task2 = goalsDetailsView.Rows[4].Cells[1].Text; //Task 2
string Task3 = goalsDetailsView.Rows[5].Cells[1].Text; //Task 3
string Task4 = goalsDetailsView.Rows[6].Cells[1].Text; //Task 4
string Task5 = goalsDetailsView.Rows[7].Cells[1].Text; //Task 5
UpdateOrAddNewRecord(goalid, tasksetid, Task1, Task2, Task3, Task4, Task5, goal, true); // call update method
BindDetailsView(); // Rebind GridView to reflect changes made
}
謝謝...我會給這個鏡頭。 – 2011-04-16 15:16:51
工作!謝謝。 – 2011-04-16 15:22:23