473,847 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

In Gridview - get ID of row

25 New Member
i make a gridview and i make a code :
delete row in gridview
Expand|Select|Wrap|Line Numbers
  1.  public bool Delete(int id, out string Msg) 
  2. {
  3. Msg = "";
  4. try
  5. {
  6. SqlServerDb sql = new SqlServerDb();// library connect
  7. sql.Connect();
  8.  
  9. string cmdText = "Delete from tbl_Status where Id=@Id";
  10.  
  11. SqlParameterList paramList = new SqlParameterList();
  12.  
  13. paramList.Add("@Id", id, SqlDbType.SmallInt);
  14. sql.ExecuteNonQuery(cmdText, SqlCommandType.Text, paramList);
  15. sql.Disconnect();
  16. return true;
  17. }
  18. catch (Exception ex)
  19. {
  20. Msg = ex.Message;
  21. return false;
  22. }
  23. }
  24.  
this funcition use delete a row in database
and i ask how to i invoke id of each row in Gridview
to pass into this function to delete row
example : I make a another function for click button
Expand|Select|Wrap|Line Numbers
  1.  
  2. protected void btn_delete_Click(object sender, EventArgs e)
  3. TMLib.Business.AddStatus status = new AddStatus();// 
  4. // i need do
  5. if( status.Delete( ?, out message);
  6. i don't know pass this value id 
  7.  
  8.  
  9. }
  10.  
Nov 8 '07 #1
4 8431
Saad Alam
27 New Member
First Set AutoGenerateDel eteButton property of gridview to true. Now you will have a link button at the end of each row in gridview. When this link button is clicked a rowdeleting event of gridview will be fired. In the row deleting event you will need to call your deletion function. In the DataKeyNames property give the name of your primary key column.
Now in the rowdeleting event of gridview, you should write code similar to this:

protected void GridView1_RowDe leting(object sender, GridViewDeleteE ventArgs e)
{
//Here you will call your deletion function
// You can get the id by using this code
//string id = GridView1.DataK eyNames.ToStrin g();
}

You can also keep the id in invisible column of gridview.
Nov 8 '07 #2
nguyenlh
25 New Member
I can delete row
but i can ask you
I have a textbox and In girdview i make a linkbutton Edit and i want when i click Edit then -- the field appear on textbox ( textbox not into gridview) and i can edit the field and after update it( table only a field ) -
Nov 9 '07 #3
athir13en
2 New Member
I cant get the id with that:
Expand|Select|Wrap|Line Numbers
  1. Dim ID As String = GridView1.DataKeyNames.ToString()..
Can any one can help.. please?
Mar 14 '08 #4
kshnbd
3 New Member
Use this
Expand|Select|Wrap|Line Numbers
  1.  
  2. string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
  3.  
Regards,

Free Online Diary
Jun 25 '08 #5

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

Similar topics

3
5680
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the GridView to allow entry of quantity and Y/N switch for
6
3044
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
7
14826
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
5
4845
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
5218
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
3
4612
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a datasource to this GridView in runtime. But I cannot
2
13204
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3013
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
6
5765
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
3
5249
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
9887
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
9730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
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...
0
10648
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10341
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
5719
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...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4529
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.