473,799 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iam not getting values I entered in the gridview for updation

2 New Member
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 1709
Frinavale
9,735 Recognized Expert Moderator Expert
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.MessageBo x in an ASP.NET application. Also, you should look into using the GridView.RowDat aBind Event to set the background colour instead of doing this in your FillGrid method.

-Frinny
Nov 20 '09 #2
sailaja71185
2 New Member
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 Recognized Expert Moderator Expert
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.Fin dControl method when the user is updating.

(Notice that I set the GridView's AutoGenerateCol umns 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.M essageBox control.

-Frinny
Nov 23 '09 #4

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

Similar topics

0
1078
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 will insert or update. So after the modifications how the correct updation is made in the database table. What the hidden mechanism is there. The updation logic is confusing Pls help me, if any articles available let me know them Thanks in...
3
3879
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 GridView control, each with its own SqlDataSource. FormView1 talks to my Opportunity table and has an ItemTemplate and an EditItemTemplate. FormView2 talks to my Activities table and has an ItemTemplate, InsertItemTemplate and an...
0
1831
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 GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { // 1)Convert the row index stored in the CommandArgument property to an Integer int index = e.RowIndex;
0
2387
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 ItemTemplate in the GridView populated with three ListItems. A Button to Submit the form.
3
15318
by: needin4mation | last post by:
In this code: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)e.Row.DataItem; // Retrieve the value for the current row.
0
331
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
1483
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
9107
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 any one please help me in doing this. thank you
1
1092
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 warning text employee id the requirement is :: user check few checkbox and onclick of that button
1
1947
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) { int i; int j; for( i = 0; i < dt.Columns.Count; i++) {
0
9689
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10495
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10248
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.