473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Iam not getting values I entered in the gridview for updation

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. using System.Data;
  2. using System.Linq;
  3. using System.Web;
  4. using System.Web.Security;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Xml.Linq;
  10. using HomeDataLayer;
  11. using System.Windows.Forms;
  12. public partial class Reminders : System.Web.UI.Page
  13. {
  14.  
  15.  
  16.  
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         if (!IsPostBack)
  20.         {
  21.             txtRemindDate .Text  = System.DateTime.Now.Date.ToShortDateString();
  22.             FillGrid();
  23.         }
  24.     }
  25.  
  26.     public void FillGrid()
  27.     {
  28.         DataTable dt = HomeManagement.SelectReminders();
  29.         if (dt != null)
  30.             if (dt.Rows.Count > 0)
  31.             {
  32.                 RemindersGrid.DataSource = dt;
  33.                 RemindersGrid.DataBind();
  34.                 for (int i = 0; i < RemindersGrid.Rows.Count; i++)
  35.                 {
  36.                     if (RemindersGrid.Rows[i].Cells[4].Text == Convert.ToString(System.DateTime.Now.Date))
  37.                     {
  38.                         RemindersGrid.Rows[i].BackColor = System.Drawing.Color.LightYellow;
  39.                         //string msg = RemindersGrid.Rows[i].Cells[1].Text;
  40.                         //msg += "<br>" + RemindersGrid.Rows[i].Cells[4].Text;
  41.                         //System.Windows.Forms.MessageBox.Show(msg);
  42.                     }
  43.                 }
  44.  
  45.             }
  46.             else
  47.             {
  48.                 RemindersGrid.DataSource = null;
  49.                 RemindersGrid.DataBind();
  50.             }
  51.     }
  52.  
  53.  
  54.     protected void submit_Click(object sender, ImageClickEventArgs e)
  55.     {
  56.         try
  57.         {
  58.             int i = HomeManagement.InsertReminder(txtIssue.Text, txtName.Text, Convert.ToDateTime(txtRemindDate.Text), System.DateTime.Now.Date );
  59.             if (i > 0)
  60.             {
  61.                 System.Windows.Forms.MessageBox.Show("Succcessfully Inserted");
  62.                  txtRemindDate .Text  = System.DateTime.Now.Date.ToShortDateString();
  63.                 txtIssue.Text = txtName.Text = "";
  64.  
  65.             }
  66.         }
  67.         catch (Exception err)
  68.         {
  69.             System.Windows.Forms.MessageBox.Show(err.ToString ());
  70.         }
  71.  
  72.     }
  73.     protected void RemindersGrid_RowEditing(object sender, GridViewEditEventArgs e)
  74.     {
  75.         RemindersGrid.EditIndex = e.NewEditIndex;
  76.         FillGrid();
  77.     }
  78.     protected void RemindersGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
  79.     {
  80.         bool flag;
  81.         if (RemindersGrid.DataSource == null)
  82.             flag = false;
  83.         else
  84.         {
  85.  
  86.         }
  87.         try
  88.         {
  89.             RemindersGrid.EditIndex = e.RowIndex;
  90.             int ID = e.RowIndex;
  91.             string name = RemindersGrid.Rows[e.RowIndex ].Cells[2].Text ;
  92.             int i = HomeManagement.UpdateReminder(RemindersGrid.Rows[e.RowIndex].Cells[5].Text, RemindersGrid.Rows[ID].Cells[2].Text, Convert.ToDateTime(RemindersGrid.Rows[ID].Cells[4].Text), Convert.ToDateTime(RemindersGrid.Rows[ID].Cells[3].Text), int.Parse(RemindersGrid.Rows[ID ].Cells[1].Text));
  93.             if (i > 0)
  94.                 MessageBox.Show("Update Successfully");
  95.         }
  96.         catch (Exception err)
  97.         {
  98.             MessageBox.Show(err.ToString());
  99.         }
  100.  
  101.  
  102.     }
  103.     protected void RemindersGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
  104.     {
  105.         int index = e.RowIndex;
  106.         FillGrid();
  107.        RemindersGrid.EditIndex = e.RowIndex;
  108.  
  109.        int i = HomeManagement.DeleteReminders(int.Parse(RemindersGrid.Rows[index].Cells[1].Text));
  110.        if (i > 0)
  111.            MessageBox.Show("Deleted Successfully");
  112.  
  113.     }
  114.     protected void RemindersGrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  115.     {
  116.        // FillGrid();
  117.         RemindersGrid.EditIndex = -1;
  118.  
  119.     }
  120. }
Can any one solve my problem?
Nov 20 '09 #1
3 1689
Frinavale
9,735 Expert Mod 8TB
Could you please post the ASP code for the GridView...I can't get a clear idea of what you are trying to do unless I see it's markup.

Aside from that, and completely unrelated to the problem, You shouldn't be using System.Windows.Forms.MessageBox in an ASP.NET application. Also, you should look into using the GridView.RowDataBind Event to set the background colour instead of doing this in your FillGrid method.

-Frinny
Nov 20 '09 #2
Hi thanks for Ur reply, here is my design code:
Expand|Select|Wrap|Line Numbers
  1.  
  2.                <asp:Panel ID="DataPanel"  runat ="server" BorderColor ="green" BorderWidth ="0px" width ="900px">
  3.           <table style="width: 883px" >
  4.           <tr>
  5.  
  6.  
  7.           <td >
  8.             <asp:Label ID="lblRemindDate" runat="server" Font-Names="Tahoma" Font-Size="12px" 
  9.                     Text="RemindDate: "></asp:Label>
  10.               </td>
  11.               <td>
  12.               <asp:TextBox ID="txtRemindDate" runat="server" Font-Names="Tahoma" 
  13.                     Font-Size="12px" TabIndex="40" BackColor="AliceBlue"></asp:TextBox>
  14.                          <cc1:CalendarExtender ID="txtRemindDate_CalendarExtender" 
  15.                                          runat="server" CssClass="MyCalendar" Enabled="True" Format="MM/dd/yyyy" 
  16.                                          PopupButtonID="ImageButtonCalendarPopupRemindDate" 
  17.                                          TargetControlID="txtRemindDate">
  18.                                      </cc1:CalendarExtender>
  19.                                      <cc1:MaskedEditExtender ID="txtRemindDate_MaskedEditExtender" 
  20.                                          runat="server" ClearMaskOnLostFocus="False" CultureAMPMPlaceholder="" 
  21.                                          CultureCurrencySymbolPlaceholder="" CultureDateFormat="" 
  22.                                          CultureDatePlaceholder="" CultureDecimalPlaceholder="" 
  23.                                          CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" 
  24.                                          Mask="99/99/9999" TargetControlID="txtRemindDate">
  25.                                      </cc1:MaskedEditExtender>
  26.                                       <asp:ImageButton ID="ImageButtonCalendarPopupRemindDate" runat="Server" 
  27.                                         AlternateText="Click to show calendar" CausesValidation="false" 
  28.                  ImageUrl="~/Resources/images/Calendar_scheduleHS.png" TabIndex="135" />
  29.  
  30.                   </td> 
  31.                   </tr> 
  32.                   <tr>
  33.                   <td >
  34.                       <asp:Label ID="lblName" runat="server" Font-Names="Tahoma" Font-Size="12px" Text="PersonName: "></asp:Label>
  35.              </td> 
  36.              <td>
  37.              <asp:TextBox ID="txtName" runat="server" Font-Names="Tahoma" 
  38.                     Font-Size="12px"
  39.                     TabIndex="40" BackColor="AliceBlue"></asp:TextBox>
  40.                     </td> 
  41.                     </tr> 
  42.                     <tr><td >
  43.                     <asp:Label ID="lblIssue" runat="server" Font-Names="Tahoma" Font-Size="12px" 
  44.                         Text="Issue: "></asp:Label></td>
  45.                         <td>
  46.               <asp:TextBox ID="txtIssue" runat="server" Font-Names="Tahoma"  TextMode ="MultiLine" 
  47.                     Font-Size="12px"
  48.                     TabIndex="40" BackColor="AliceBlue" style="margin-left: 4px" Width="271px"></asp:TextBox>
  49.              </td> 
  50.              </tr> 
  51.              <tr><td class="style1">
  52.  
  53.  
  54.                 <asp:ImageButton ID="submit" runat ="server" 
  55.                     ImageUrl ="~/Resources/images/submit_button.gif" AlternateText ="Add Reminder"
  56.                  onclick="submit_Click" />
  57.              </td> 
  58.              </tr>
  59.              </table>
  60.  
  61.                  </asp:Panel> 
  62.  
  63.  
  64.           <asp:Panel ID="GridPanel" runat ="server" style="z-index :105;" BorderColor ="green" BorderWidth ="0px" width ="900px">
  65.  
  66.           <asp:Label ID="ExistingReminders" Font-Bold ="true" Font-Names ="Tahoma" Font-Size ="13px" runat ="server" 
  67.  Text ="Existing Reminders" ></asp:Label> 
  68.  <asp:GridView ID="RemindersGrid"  runat ="server" CellPadding="4" ForeColor="#333333" GridLines="None" 
  69.                           AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
  70.                           onrowdeleting="RemindersGrid_RowDeleting" 
  71.                           onrowediting="RemindersGrid_RowEditing" 
  72.                           onrowupdating="RemindersGrid_RowUpdating" 
  73.                           onrowcancelingedit="RemindersGrid_RowCancelingEdit"  > 
  74.  
  75.      <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  76.      <RowStyle BackColor="#F7F6F3" ForeColor="#333333"  Font-Size ="12px" Font-Names ="Tahoma"/>
  77.      <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  78.      <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  79.      <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  80.      <EditRowStyle BackColor="#999999" />
  81.      <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  82.  
  83.  
  84.   </asp:GridView>

I've no problem with message box.
Nov 21 '09 #3
Frinavale
9,735 Expert Mod 8TB
I think I might know why you're having a problem.
You have no EditTemplate specified for your columns.

Your GridView should look something like:
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="RemindersGrid"  runat ="server" CellPadding="4"
  2.       ForeColor="#333333" GridLines="None" 
  3.       AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
  4.       AutoGenerateColumns="False"
  5.  
  6.             onrowdeleting="RemindersGrid_RowDeleting" 
  7.             onrowediting="RemindersGrid_RowEditing" 
  8.             onrowupdating="RemindersGrid_RowUpdating" 
  9.             onrowcancelingedit="RemindersGrid_RowCancelingEdit"  > 
  10.  
  11.   <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  12.   <RowStyle BackColor="#F7F6F3" ForeColor="#333333"  Font-Size ="12px" Font-Names ="Tahoma"/>
  13.   <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  14.   <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  15.   <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  16.   <EditRowStyle BackColor="#999999" />
  17.   <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  18.  
  19.   <Columns>
  20.     <asp:TemplateField headertext="Column1">
  21.       <ItemTemplate>
  22.         <asp:Label id="NameLabel" Text= '<%# Eval("name") %>' runat="server"/>         
  23.       </ItemTemplate>
  24.       <EditTemplate>
  25.         <asp:TextBox id="NameTextBox" Text= '<%# Eval("name") %>' runat="server"/>    
  26.       </EditTemplate>
  27.     </asp:TemplateField>
  28.   </Columns>
  29.  </asp:GridView>
Notice how I have added a TemplateField to the Columns section of the GridView?

This TemplateField tells the GridView how to display the data that it's bound to.

In this case the TemplateField specifies that the data in the column "name" should be displayed in a Label if the user is just viewing the GridView. It also specifies that the data in column "name" should be displayed in a TextBox if the user is editing the GridView.

Now you can let the user edit the data.
You can get the values the user entered using the GridViewRow.FindControl method when the user is updating.

(Notice that I set the GridView's AutoGenerateColumns property to False. If you don't do this then 2 columns will appear for the "name" column: one automatically generated, and the other displayed in the TemplateField)


For example:
Expand|Select|Wrap|Line Numbers
  1. protected void RemindersGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
  2.      {
  3.          bool flag;
  4.          if (RemindersGrid.DataSource == null)
  5.              flag = false;
  6.          else
  7.          {
  8.  
  9.          }
  10.          try
  11.          {
  12.              RemindersGrid.EditIndex = e.RowIndex;
  13.              int ID = e.RowIndex;
  14.              TextBox nameTextBox = (TextBox) RemindersGrid.Rows[e.RowIndex ].FindControl("NameTextBox");
  15.              string name = nameTextBox.Text ;
  16. //...............................................
  17.          }
  18.          catch (Exception err)
  19.          {
  20.              MessageBox.Show(err.ToString());
  21.          }
  22.      }
Now, regarding the MessageBox, it will work ok in Internet Explorer but it will not work in any other browser. The MessageBox is a Windows.Forms control not a Windows.Web control.

You should not be using Windows.Forms controls in a web application.

Even if the end user is displayed the MessageBox it's not a good idea.
The reason is because an ActiveX control would be required in order to display the MessageBox. This means that your website is restricted to being viewed only in Internet Explorer. Also, ActiveX controls are pron to security flaws that may open the end user computer up to vulnerabilities. ActiveX controls are not trusted and many users have them turned off...which means that the end user is unlikely to be able to see the message box.


I recommend placing a Label on the page and setting it's Text to any error messages instead of using the Windows.Forms.MessageBox control.

-Frinny
Nov 23 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lakshmi Narayanan.R | last post by:
Hi Experts I am new to .NET. I need great explanation for "the updation in the disconnected data". How it is handled. That is, if mutiple user is interacting with the data, one will delete another...
3
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a...
0
by: Mike P | last post by:
How do you get access to the values you have entered under edit mode in a gridview? I only seem to be able to access the values prior to them being edited. protected void...
0
by: reddog | last post by:
Getting the SelectedIndex of a DropDownlist under the ItemTemplate in a GridView is harder than I thought it would be. I have: A Gridview of n rows bound to a DataSet. A DropDownList as an...
3
by: needin4mation | last post by:
In this code: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView rowView =...
0
by: maflatoun | last post by:
Hey guys, I'm using ASP.NET 2.0 GridView for the first time. I have the following setup On the .aspx side I have this in my GridView <asp:TemplateField HeaderText="New"> <ItemTemplate>
1
by: maflatoun | last post by:
ey guys, I'm using ASP.NET 2.0 GridView for the first time. I have the following setup On the .aspx side I have this in my GridView <asp:TemplateField HeaderText="New"> <ItemTemplate>
4
by: rohitscripts | last post by:
I need to fill my gridview with the values that are entered into textboxes. For this, i thought to fill a datatable with the textbox values first and then bind this datatable to my gridview. Could...
1
by: Ratnesh lal | last post by:
Hi, I have a gridview in my page; the source of gridview is datatable returned by a function in businesslogic class inside App_code folder. gridview contains:: checkboxes ...
1
by: neobonzi | last post by:
Hello! I'm dynamically creating a GridView bound to a datatable using custom template columns using the following method: protected void ShowGrid(DataTable dt) { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.