User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,502 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,679 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1189 | Replies: 15 | Solved
Reply
Join Date: Mar 2008
Posts: 34
Reputation: priyamsc is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
priyamsc priyamsc is offline Offline
Light Poster

problem in updating the gridview

  #1  
Jun 4th, 2008
hi,
i have used gridview in asp.net 2005 wit c#.i need to update my datas.in tat i hv placed dropdownlist,checkbox controls.but its not updating the datas.when i edit the row,we have dropdownlist but not tat database value.so when i edit the row the database value should be in dropdown list.when i click update link i got this error.The GridView 'GridView1' fired event RowUpdating which wasn't handled.so pls help me to do this.
this is coding
-----------------
  1. protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
  2. { GridViewRow gv = null;
  3. string k = string.Format(GridView1.Rows[gv.RowIndex].Cells[4].Text);
  4. Response.Write(k);
  5. TextBox t1, t2, t3, t4, t5,t6,t7,t8,t9,t10,t11;
  6. DropDownList d1, d2, d3, d4,d5;
  7. CheckBox cdr, cdrw, cdvdr, cdvdrw, cfdd, cinter, cwa;
  8. t1 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[5].Controls[1];
  9. t2 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[6].Controls[1];
  10. t3 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[7].Controls[1];
  11. t4 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[8].Controls[1];
  12. t5 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[9].Controls[1];
  13. t6 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[10].Controls[1];
  14. t7 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[11].Controls[1];
  15. t8 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[18].Controls[1];
  16. t9 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[20].Controls[1];
  17. t10 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[21].Controls[1];
  18. t11 = (TextBox)GridView1.Rows[gv.RowIndex].Cells[22].Controls[1];
  19. d1 = (DropDownList)GridView1.Rows[gv.RowIndex].Cells[0].Controls[0];
  20. d2 = (DropDownList)GridView1.Rows[gv.RowIndex].Cells[1].Controls[0];
  21. d3 = (DropDownList)GridView1.Rows[gv.RowIndex].Cells[2].Controls[0];
  22. d4 = (DropDownList)GridView1.Rows[gv.RowIndex].Cells[3].Controls[0];
  23. d5 = (DropDownList)GridView1.Rows[gv.RowIndex].Cells[23].Controls[0];
  24. cdr = (CheckBox)GridView1.Rows[gv.RowIndex].Cells[12].Controls[2];
  25. cdrw = (CheckBox)GridView1.Rows[gv.RowIndex].Cells[13].Controls[2];
  26. cdvdr =(CheckBox)GridView1.Rows[gv.RowIndex].Cells[14].Controls[2]; cdvdrw=(CheckBox)GridView1.Rows[gv.RowIndex].Cells[15].Controls[2];
  27. cfdd = (CheckBox)GridView1.Rows[gv.RowIndex].Cells[16].Controls[2];
  28. cinte =(CheckBox)GridView1.Rows[gv.RowIndex].Cells[17].Controls[2];
  29. cwa = (CheckBox)GridView1.Rows[gv.RowIndex].Cells[19].Controls[2];
  30. int cd_r = 0, cd_rw = 0, dvd_r = 0, dvd_rw = 0, fdd = 0, inter = 0, wa = 0;
  31. if (cdr.Checked)
  32. { cd_r = 1; }
  33. if (cdrw.Checked==true)
  34. { cd_rw = 1; }
  35. if (cdvdr.Checked==true)
  36. { dvd_r = 1; }
  37. if (cdvdrw.Checked == true)
  38. { dvd_rw = 1; }
  39. if (cfdd.Checked == true)
  40. { fdd = 1; }
  41. if (cinter.Checked == true)
  42. { inter = 1; }
  43. if (cwa.Checked == true)
  44. { wa = 1; }
  45. string upd="update reg_laptop set block='"+d1.SelectedValue+"',location='"+d2.SelectedValue+"',department='"+d3.SelectedValue +"',pcname='"+d4.SelectedValue+"',os='"+t1.Text+"',procmodel='"+t2.Text +"',procspeed='"+t3.Text+"',ram='"+t4.Text+"',harddisk='"+t5.Text+"',cpuno='"+t6.Text +"',monino='"+t7.Text +"',cd_r="+cd_r+",cd_rw="+cd_rw+",dvd_r="+dvd_r +",dvd_rw="+dvd_rw+",fdd="+fdd+",internetconnection="+inter+",dateofpurchase='"+t8.Text+"',waranty_amc="+wa+",frmdate='8/5/2003',todate='8/5/2009',compname='"+d5.SelectedValue+"',contactperson='"+t9.Text+"' where ipaddress='"+k+"'";
  46. cmd = new SqlCommand(upd, con);
  47. cmd.ExecuteNonQuery();
  48. Response.Write("ur datas r updated");
  49. GridView1.EditIndex = -1;
  50. binddata(); }
===========================================================
  1. protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) {
  2. GridView1.EditIndex = e.NewEditIndex;
  3. binddata(); }

thank you
Last edited by peter_budo : Jun 4th, 2008 at 3:46 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 39
Reputation: srikanthkadem is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
srikanthkadem srikanthkadem is offline Offline
Light Poster

Re: problem in updating the gridview

  #2  
Jun 4th, 2008
hi,
can u try to write that whole code in row updating instead of rowupdated.
got solution ?, please mark the thread as Solved. Thanks & Regards,
srikanth kadem
srikanthkadem@rediffmail.com
Reply With Quote  
Join Date: May 2008
Posts: 1
Reputation: shivakanungo26 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
shivakanungo26 shivakanungo26 is offline Offline
Newbie Poster

Re: problem in updating the gridview

  #3  
Jun 4th, 2008
tring the code in rowupdating event
Reply With Quote  
Join Date: Mar 2008
Posts: 34
Reputation: priyamsc is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
priyamsc priyamsc is offline Offline
Light Poster

Re: problem in updating the gridview

  #4  
Jun 4th, 2008
ya now i tried in updating event. its working.but again i have error .
in this line..
GridViewRow gv = null;
string k = string.Format(GridView1.Rows[gv.RowIndex].Cells[4].Text);

bec i have created gv for gridviewrow... and assigned null.
If i don't give gv =null it show an error
so pls give suggestion for rectify this error.
Reply With Quote  
Join Date: Mar 2008
Posts: 34
Reputation: priyamsc is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
priyamsc priyamsc is offline Offline
Light Poster

Re: problem in updating the gridview

  #5  
Jun 4th, 2008
hi ,
instead of gv i use e.so i rectified tat error.
but one more error is
cdr = (CheckBox)GridView1.Rows[gv.RowIndex].Cells[12].Controls[2];
because in database i used bit value.tat is 0 or 1.and if it is in grid view then it shows No or Yes. when i edit tat it shows chek box .
so when i check the check box 1 should be stored in database
so pls help me to do this

thanking you
Last edited by priyamsc : Jun 4th, 2008 at 5:09 am.
Reply With Quote  
Join Date: Mar 2008
Posts: 39
Reputation: srikanthkadem is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
srikanthkadem srikanthkadem is offline Offline
Light Poster

Re: problem in updating the gridview

  #6  
Jun 4th, 2008
hey priya,
try like this
checkbox cb=(checkbox)gridview1.findcontrol("checkbox1");
if(cb.checked)
{
//so so
}
else
{
//so so
}
may it works...
got solution ?, please mark the thread as Solved. Thanks & Regards,
srikanth kadem
srikanthkadem@rediffmail.com
Reply With Quote  
Join Date: Mar 2008
Posts: 39
Reputation: srikanthkadem is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
srikanthkadem srikanthkadem is offline Offline
Light Poster

Re: problem in updating the gridview

  #7  
Jun 4th, 2008
Note:iam not intrested in case sensitivity...use proper cases as c# is case sensitive....
got solution ?, please mark the thread as Solved. Thanks & Regards,
srikanth kadem
srikanthkadem@rediffmail.com
Reply With Quote  
Join Date: Mar 2008
Posts: 34
Reputation: priyamsc is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
priyamsc priyamsc is offline Offline
Light Poster

Re: problem in updating the gridview

  #8  
Jun 4th, 2008
ya. i gave like this as you told.
cdr = (CheckBox)GridView1.FindControl("chk_cdr");
but its showing an error.when i trace it value cdr = null
and i got this error Object reference not set to an instance of an object
how can i get the 1 when i check the checkbox

i tried in checkedchanged event..tat event also is not working. shows the same error

thank you sir,
Last edited by priyamsc : Jun 4th, 2008 at 6:31 am.
Reply With Quote  
Join Date: Mar 2008
Posts: 39
Reputation: srikanthkadem is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
srikanthkadem srikanthkadem is offline Offline
Light Poster

Re: problem in updating the gridview

  #9  
Jun 4th, 2008
hey priya,
can u ones post the .aspx page code...i will check 1s so that i will get some idea....
got solution ?, please mark the thread as Solved. Thanks & Regards,
srikanth kadem
srikanthkadem@rediffmail.com
Reply With Quote  
Join Date: Mar 2008
Posts: 34
Reputation: priyamsc is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
priyamsc priyamsc is offline Offline
Light Poster

Re: problem in updating the gridview

  #10  
Jun 4th, 2008
Ya , this is aspx code sir,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="reg_editlaptop.aspx.cs" Inherits="reg_editlaptop" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"
Height="219px" Width="1367px" AllowSorting="True" EnableTheming="True" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating">
<FooterStyle BackColor="Tan" />
<Columns>
<asp:TemplateField HeaderText="Block">
<EditItemTemplate>
&nbsp;
<aspropDownList ID="ddl_block" runat="server" AutoPostBack="True" Width="130px" DataTextField ="descriptions" DataValueField ="sid" DataSource="<%#loadblock()%>" AppendDataBoundItems="True" OnSelectedIndexChanged="ddl_block_SelectedIndexChanged">
<asp:ListItem>--------Select--------</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("block") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<EditItemTemplate>
&nbsp;<aspropDownList ID="ddl_loc" runat="server" DataSource ="<%#loadloc()%>" DataTextField ="descriptions" DataValueField ="sid" AppendDataBoundItems="True" AutoPostBack="True"
Width="130px">
<asp:ListItem>--------Select--------</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("location") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department">
<EditItemTemplate>
&nbsp;<aspropDownList ID="ddl_dep" runat="server" DataSource ="<%#loaddep()%>" DataTextField="descriptions" DataValueField ="sid" AppendDataBoundItems="True" AutoPostBack="True"
Width="130px">
<asp:ListItem>--------Select--------</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("department") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sys-Name">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" DataSource="<%#loadpc()%>" DataTextField="descriptions" DataValueField="sid" AutoPostBack="True" Width="130px">
<asp:ListItem>--------Select--------</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("pcname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ipaddress" HeaderText="IP-Address" ReadOnly="True" />
<asp:BoundField DataField="os" HeaderText="OS" />
<asp:BoundField DataField="procmodel" HeaderText="Processor Model" />
<asp:BoundField DataField="procspeed" HeaderText="Processor Speed" />
<asp:BoundField DataField="ram" HeaderText="Ram" />
<asp:BoundField DataField="harddisk" HeaderText="Hard Disk" />
<asp:BoundField DataField="cpuno" HeaderText="Cpu No." />
<asp:BoundField DataField="monino" HeaderText="Monitor No." />
<asp:TemplateField HeaderText="CD-R">
<EditItemTemplate>
<asp:CheckBox ID="chk_cdr" runat="server" OnCheckedChanged="chk_cdr_CheckedChanged" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("cd_r") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CD_RW">
<EditItemTemplate>
<asp:CheckBox ID="chk_cdrw" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("cd_rw") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DVD_R">
<EditItemTemplate>
<asp:CheckBox ID="chk_dvdr" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("dvd_r") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DVD_RW">
<EditItemTemplate>
<asp:CheckBox ID="chk_dvdrw" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("dvd_rw") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FDD">
<EditItemTemplate>
<asp:CheckBox ID="chk_fdd" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("fdd") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Internet">
<EditItemTemplate>
<asp:CheckBox ID="chk_ineter" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("internetconnection") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="dateofpurchase" HeaderText="DOP" />
<asp:TemplateField HeaderText="W/A">
<EditItemTemplate>
<asp:CheckBox ID="chk_wa" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("wa") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="frmdate" HeaderText="From Date" />
<asp:BoundField DataField="todate" HeaderText="To Date" />
<asp:TemplateField HeaderText="Company Name">
<EditItemTemplate>
<aspropDownList ID="ddl_compname" runat="server" AutoPostBack="True" Width="123px">
<asp:ListItem>---------Select--------</asp:ListItem>
<asp:ListItem>Hcl</asp:ListItem>
<asp:ListItem>Accel</asp:ListItem>
<asp:ListItem>MasterMind</asp:ListItem>
<asp:ListItem>Dell</asp:ListItem>
<asp:ListItem>logitech</asp:ListItem>
<asp:ListItem>Samsung</asp:ListItem>
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("compname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="contactperson" HeaderText="Contact Person" />
<asp:CommandField ShowEditButton="True" />
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
&nbsp;<br />

</div>
</form>

</body>
</html>
thanking you,
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC