a value that shows in select mode disappears in edit mode from a gridview column
Posted
by
Jbob Johan
on Stack Overflow
See other posts from Stack Overflow
or by Jbob Johan
Published on 2012-06-03T22:28:27Z
Indexed on
2012/06/03
22:40 UTC
Read the original article
Hit count: 245
i have a gridview(GridView1) with a few Bound Fields first one is Date (ActivityDate) from a table named "tblTime" i have managed to add one extra colum (manually), that is not bound that shows dayInWeek value according to the "ActivityDate" field programtically in CodeBehind but when i enter into Edit Mode , all Bound fields are showing their values correctly but the one column i have added manually will not show the value as it did in "select mode"(first mode b4 trying to edit) while im not a great dibbagger i have manged to view the cell's value (GridView1.Rows[e.NewEditIndex].Cells[1].Text) which does hold on to the day in week value but it does not appear in gridview edit mode only
this is some of the code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "?????"; //Activity Date (in hebrew)
e.Row.Cells[1].Text = "??? ?????"; //DayinWeek
e.Row.Cells[2].Text = "??????"; //ActivityType (work seek vacation) named Reason
e.Row.Cells[3].Text = "??? ?????"; //time finish (to Work)
e.Row.Cells[4].Text = "??? ?????"; //Time out (of work)
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToBoolean(ViewState["theSubIsclckd"]) == true) //if submit button clicked
{
try
{
string twekday1 = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ActiveDate"));
twekday1 = twekday1.Remove(9, 11); //geting date only without the time- portion
string[] arymd = twekday1.Split('/'); // spliting [d m y] in order to make
int day = Convert.ToInt32(arymd[1]); // it into [m d y] ...also requierd
int month = Convert.ToInt32(arymd[0]); // when i update the table
int year = Convert.ToInt32(arymd[2]);
DateTime ILDateInit = new DateTime(year, month, day); //finally extracting Day
CultureInfo ILci = CultureInfo.CreateSpecificCulture("he-IL"); // in week
//from the converted activity date
string MyIL_DayInWeek = ILDateInit.ToString("dddd", ILci);
ViewState["MyIL_DayInWeek"] = MyIL_DayInWeek;
e.Row.Cells[1].Text = MyIL_DayInWeek;
string displayReason = DataBinder.Eval(e.Row.DataItem, "Reason").ToString();
e.Row.Cells[2].Text = displayReason;
}
catch (System.Exception excep)
{
Js.functions.but bb = new Js.functions.but();
bb.buttonName = "rex"; bb.documentwrite = true; bb.testCsVar = excep.ToString();
bb.f1(bb);
// this was supposed to throw exep in javaScript injected from code behid - alert
} // just in case..
}
}
so that works for the non edit period of time then when i hit the edit ... no day in week shows
THE aspX - after selcting date... name etc' , click on button to display gridview:
<asp:Button ID="TheSubB" runat="server" Text="???" onclick="TheSubB_Click" />
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" onrowediting="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
GridLines="None" AutoGenerateColumns="False" DataKeyNames="tId"
DataSourceID="SqlDataSource1"
style="z-index: 1; left: 0%; top: 0%; position: relative; width: 812px; height: 59px; font-family:Arial; text-align: center;"
AllowSorting="True" >
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:BoundField DataField="ActiveDate" HeaderText="ActiveDate"
SortExpression="ActiveDate" ControlStyle-Width="70"
DataFormatString="{0:dd/MM/yyyy}" >
<ControlStyle Width="70px" />
</asp:BoundField>
<asp:TemplateField HeaderText="???.???.??"> <EditItemTemplate>
<asp:TextBox ID="dayinW_EditTB" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="dayInW_editLabel" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Reason" HeaderText="???? ?????"
SortExpression="Reason" ControlStyle-Width="50">
<ControlStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="TimeOut" HeaderText="TimeOut"
SortExpression="TimeOut" ControlStyle-Width="50" DataFormatString="{0:HH:mm}" >
<ControlStyle Width="50px"></ControlStyle>
</asp:BoundField>
<asp:BoundField DataField="TimeIn" HeaderText="TimeIn" SortExpression="TimeIn"
ControlStyle-Width="50" DataFormatString="{0:HH:mm}" >
<ControlStyle Width="50px"></ControlStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="????" >
<EditItemTemplate>
<asp:ImageButton width="15" Height="15" ImageUrl="~/images/edit.png" runat="server" CausesValidation="True" CommandName="Update" Text="Update">
</asp:ImageButton>
<asp:ImageButton Width="15" Height="15" ImageUrl="images/cancel.png" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel">
</asp:ImageButton>
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton width="25" Height="15" ImageUrl="images/edit.png" ID="EditIB" runat="server" CausesValidation="False" CommandName="Edit" AlternateText="????"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="???">
<ItemTemplate>
<asp:ImageButton width="15" Height="15" ImageUrl="images/Delete.png" ID="DeleteIB" runat="server" CommandName="Delete" AlternateText="???" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
© Stack Overflow or respective owner