我的意圖是切換形成一個int-表示月份值 (因爲它是在數據庫表)gridview的列值操縱
轉換它(在GridView中顯示)作爲字符串(月份名稱) 並返回它以int形式返回數據庫(轉換回原始類型,以int表示的月份)。
這些都是在我的GridView中的相關要素,
<asp:GridView ID="GV_DaysPerMonth" runat="server" DataSourceID="dsWorkDayPerMonth"
AutoGenerateColumns="False" DataKeyNames="recordID" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None" Font-Names="arial" PageSize="12"
OnRowDataBound="GV_DaysPerMonth_RowDataBound"
OnRowEditing="GV_DaysPerMonth_RowEditing"
OnRowUpdating="GV_DaysPerMonth_RowUpdating">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="חודש" ControlStyle-Width="100" HeaderStyle-Width="120" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# Eval("theMonth")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBX_theMonth" runat="server" Text='<%# Bind("theMonth")%>' />
</EditItemTemplate>
<asp:GridView ID="GV_DaysPerMonth" runat="server" DataSourceID="dsWorkDayPerMonth"
AutoGenerateColumns="False" DataKeyNames="recordID" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None" Font-Names="arial" PageSize="12"
OnRowDataBound="GV_DaysPerMonth_RowDataBound"
OnRowEditing="GV_DaysPerMonth_RowEditing"
OnRowUpdating="GV_DaysPerMonth_RowUpdating">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Current Month" ControlStyle-Width="100" HeaderStyle-Width="120" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%# Eval("theMonth")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TBX_theMonth" runat="server" Text='<%# Bind("theMonth")%>' />
</EditItemTemplate>
我使用這些輔助方法從代碼
public static CultureInfo ILci = CultureInfo.CreateSpecificCulture("he-IL");
public static string GetMonthName(int mInt)
{
DateTime fullDate = new DateTime(2012, mInt, 2);
string[] tempDayArray = fullDate.ToString("MMMM", ILci).Split(' ');
return tempDayArray[0];
}
public static int GetMonthAsInt(string mStr)
{
return DateTime.ParseExact(mStr, "MMMM", ILci).Month;
背後來實現這一SIMPL特林e任務,但幾乎沒有錯誤,我想以一個例子來說明如何以正確的方式實現它。 我認爲這是簡單的因果顯示INT通過
<%# manipulation Function(Eval("columnName")) %>
會「只是工作」
,但它與綁定(「列名」)試圖
當它變得過於複雜,我作爲福利局 我錯誤的假設值是在細胞[1]時,它實際上是在細胞[0]
所以我確實在正常模式下 也在編輯模式下雖然不可編輯但通過標籤視圖模式,而不是一個TextBox
protected void GV_DaysPerMonth_RowDataBound(object sender, GridViewRowEventArgs e)
{
RowNum = GV_DaysPerMonth.Rows.Count;
GridViewRow CurRow = e.Row; // Retrieve the current row.
if (CurRow.RowType == DataControlRowType.DataRow)
{
bool isntEmptyMonth = string.IsNullOrEmpty(e.Row.Cells[0].Text) == false;
if (isntEmptyMonth)
{
e.Row.Cells[1].Text = RobCS.RDates.GetMonthName(Convert.ToInt32((e.Row.Cells[0].Text)));
}
}
}
so i think it might be the **missing handler for the edit mode** ?
感謝您的信息,雖然問題不是**如何maipulate **而是如何實現正確的方式發送回數據庫的時候編輯爲名稱需要返回爲int,因爲它本來是 – LoneXcoder
爲什麼不能你在databind gridview之前將月份數字轉換爲月份名稱?從數據庫獲取數據時,可以將存儲過程本身的月份數轉換爲月份名稱,也可以在將數據集綁定到gridview之前使用C#進行。對於編輯,您可以捕獲GridView_onRowEdited事件,並使用DateTime.ParseExact(monthName,「MMMM」,CultureInfo.CurrentCulture)將該字符串轉換爲int。月份 – tranceporter
這正是我遇到的困難:「陷阱GridView_onRowEdited事件,並將字符串轉換爲int使用DateTime.ParseExact'「我已經有一個事件,因爲我的語法缺乏知識,如果我只能有一個更新前的價值的例子,然後更新後的值。 – LoneXcoder