CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: Date Entered: 9/26/2007 10:01:57 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 10 Views: 203 Favorited: 0 Favorite
11 Items, 1 Pages 1 |< << Go >> >|
"hardy" <>
NewsGroup User
how to take row in gridview9/26/2007 10:01:57 AM

0

hello all..,

 my problem like that: 

shipperid        name                                         status

    1                andy             sendbutton            checkbox

    2                 budy            sendbutton            checkbox

 

the problem i have is when i click sendbutton in row two,the data row 1 replace data row 2 like that:

shipperid        name                                         status

    1                andy             sendbutton            checkbox

    2                andy             sendbutton            checklist(true)

this problem maybe from my code row..

this is my code:

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "send" Then

            Me.SqlDataSource1.Update()
        End If
    End Sub

Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
        Dim company As String = Me.GridView1.Rows(0).Cells(1).Text
        e.Command.Parameters("@companyname").Value = company
        e.Command.Parameters("@status").Value = "true"
    End Sub

End Class

how can i change the that row? so i can update data according data row that i choose...

plss... thx.. 

 

"ecbruck" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 12:37:37 PM

0

This example will show you how to use a SqlDataSource with a GridView for selecting, updating, and deleting. There is no code-behind necessary unless you want to add any error handling or updating and deleting confirmations. 

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" autogeneratedeletebutton="true"
	autogenerateeditbutton="true" datakeynames="ShipperID" datasourceid="SqlDataSource1"
	emptydatatext="There are no data records to display.">
	<columns>
		<asp:boundfield datafield="ShipperID" headertext="ShipperID" readonly="True" sortexpression="ShipperID" />
		<asp:boundfield datafield="CompanyName" headertext="CompanyName" sortexpression="CompanyName" />
		<asp:boundfield datafield="Phone" headertext="Phone" sortexpression="Phone" />
	</columns>
</asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
	deletecommand="DELETE FROM [Shippers] WHERE [ShipperID] = @ShipperID" providername="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>"
	selectcommand="SELECT [ShipperID], [CompanyName], [Phone] FROM [Shippers]" updatecommand="UPDATE [Shippers] SET [CompanyName] = @CompanyName, [Phone] = @Phone WHERE [ShipperID] = @ShipperID">
	<updateparameters>
		<asp:parameter name="CompanyName" type="String" />
		<asp:parameter name="Phone" type="String" />
		<asp:parameter name="ShipperID" type="Int32" />
	</updateparameters>
	<deleteparameters>
		<asp:parameter name="ShipperID" type="Int32" />
	</deleteparameters>
</asp:sqldatasource>
And the way I created this was very simple. I created a new connection for my Northwind database within my Server Explorer window of Visual Studio. 
Then, I located the table I was interested in working with, and dragged it to my working area. That's it!

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

Please remember to 'Mark as Answer' if this post answered your question!
"hardy" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 2:37:43 PM

0

ok, thx ecbruck...

my true problem is like ....

i add status to your shipper table.

status display in gridview use checkboxfield..

checkboxfield can not be add use edit columns, but use add new column...

i am not use select,edit,delete that have provide by gridview because i want to checklist automatic to checkboxfield when i click button in gridview... 

my gridview like this:

shipperid        companyname        phone                               status

      1                microsoft             12345       button          checkboxfield

      2                sony                    7890        button          checkboxfield

 

i want when i click button in row two, the checkboxfield in row two be checklist like that:

 

shipperid        companyname        phone                               status

      1                microsoft             12345       button          checkboxfield

      2                sony                    7890        button          checklist

how can i do that?

plss.. thx... 


 

"ecbruck" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 2:57:26 PM

0

So when you press this Button, you simply want to change a field in your database to read "checklist" correct. If so, you create a Click event handler for this Button. In that handler, retrieve a reference to the Button using the sender parameter. From that reference, retrieve a reference to the GridViewrow the Button is in by casting the Button.NamingContainer property to a GridViewRow. From that reference you can retrieve the current RowIndex and then the DataKey for that row. From there, it's a simple matter of updating your database.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

Please remember to 'Mark as Answer' if this post answered your question!
"hardy" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 3:53:16 PM

0

 hello ec...

namingcontainer? can u give me code like u say? because i am difficult to undestand the english... 

my click event : because the button create by gridview, so it's use row command event..

 Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "update" Then

            Me.SqlDataSource1.Update()
        End If
    End Sub

 Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
        Dim company As String = Me.GridView1.Rows(index).Cells(1).Text  
        Dim phone As integer = Me.GridView1.Rows(index).Cells(2).Text
        e.Command.Parameters("@companyname").Value = company
        e.Command.Parameters("@phone").Value = phone
        e.Command.Parameters("@status").Value = "true"
    End Sub

if u can give me about index code, it 100% working...

my problem is only index... 

plss..

thx... 

"ecbruck" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 4:56:33 PM

0

If your clicking a Button or LinkButton that has "Update" for the CommandName, then use the GridView.RowUpdating event. This event handler provides the GridViewUpdateEventArgs class which contains a RowIndex property for which you can use to obtain the GridViewRow currently being updated.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

Please remember to 'Mark as Answer' if this post answered your question!
"hardy" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 6:53:07 PM

0

ec...,

i don't know how to use rowindex... it can update, but can not update data according data that we choose...

i have try many..many times... if u give code about index, it can work 1000%...

my detail problem display like that:

shipperid        companyname        phone                               status

      1                microsoft             12345       button          checkboxfield

      2                sony                    7890        button          checkboxfield

      3                bandai                435345      button          checkboxfield
 

 when click button in row 3, it display:

 

shipperid        companyname        phone                               status

      1                microsoft             12345       button          checkboxfield

      2                sony                    7890        button          checkboxfield

      3                microsoft             12345       button          checklist

if i click button row2, it display:

 

shipperid        companyname        phone                               status

      1                microsoft             12345       button          checkboxfield

      2                microsoft             12345       button          checklist

      3                microsoft             12345       button          checklist

from that, we know the row1 replace all row data that we click their button... it because my index code is wrong...

i have change it many times, but it can not too. sometimes row3 replace alldata .. 

this is code:

Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
        Dim index As Integer = Me.GridView1.Rows(0).Cells(0).Text
        Dim company As String = Me.GridView1.Rows(index).Cells(1).Text  
        Dim phone As integer = Me.GridView1.Rows(index).Cells(2).Text
        e.Command.Parameters("@companyname").Value = company
        e.Command.Parameters("@phone").Value = phone
        e.Command.Parameters("@status").Value = "true"
    End Sub

i have use many way, but don't know how to get index row...

     Dim index As Integer = Me.GridView1.selectedrow

    Dim index As Integer = Me.GridView1.selecteindex

      Dim index As Integer = Me.GridView1.selectevalue

      Dim index As Integer = Me.GridView1.rowcommand

and other...

pls ec........................

thx... 

 

 

"ecbruck" <>
NewsGroup User
Re: how to take row in gridview9/26/2007 7:57:08 PM

0

Sorry, but within the SqlDataSource.Updating event, we have no idea what row is currently being updated. That's why you must either use the GridView.RowUpdating event or the GridView.RowCommand event to retrieve the currently updated row. There's no way around it.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

Please remember to 'Mark as Answer' if this post answered your question!
"hardy" <>
NewsGroup User
yessssss9/26/2007 8:26:20 PM

0

hello ec..

according u, it can not update row in GridView.RowUpdating event.maybe u are right...

so i use session to take data row index from row command event

this is code for update the row:

dim index as integer=convert.toint32(e.commandargument)

but it's only for row command event , so use session...

session("index")=index

Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
     
        Dim company As String = Me.GridView1.Rows(session("index")).Cells(1).Text  
        Dim phone As integer = Me.GridView1.Rows(session("index")).Cells(2).Text
        e.Command.Parameters("@companyname").Value = company
        e.Command.Parameters("@phone").Value = phone
        e.Command.Parameters("@status").Value = "true"
    End Sub

 now it can works...

ok..

thx... 

ec, i have one more question, 

in the phone, if i insert numeric more 9digit, it error ...

my type data is integer in phone... 

how i can insert more 9 digit? 

"ecbruck" <>
NewsGroup User
Re: yessssss9/27/2007 12:06:47 PM

0

Don't ever use an Integer for a Phone field. Use a VARCHAR field.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

Please remember to 'Mark as Answer' if this post answered your question!
"hardy" <>
NewsGroup User
Re: yessssss9/27/2007 6:03:50 PM

0

it like we always use type varchar in create componen database....

ok, thx very much ec...

 

11 Items, 1 Pages 1 |< << Go >> >|


Free Download:













how to expand and collapse node by clicking on text.

can't find user control

how can i add css menus in masterpage table.

menu control and images (png)

sitemappath

theme and post-back

custom vertical menu

removing master page at runtime

expand and collapse in tree view navigation control

how do i set the master page background image programmatically?

skin error?

where to declare namespace using inline script blocks?

wiered *** with tree view

what format stylesheet reference in masterpage?

can only click on text of menu items

accessing properties on masterpage from content page

share masterpage between sites?

masterpages and usercontrols - object reference not set

user controls within the master page

css on masterpage and content page

system.web.administration.navigationbar

master with updatepanel + content with fileupload

how to replicate the msdn web site structure

possible bug report: combination of global themes, css, png images, and ie7?

fileupload control is not working with masterpages

programmatic themes

asp.net catch auto rename of form field controls inside of content controls that are called into master page placeholders

master page properties

master page control question

site appearance ie7

masterpage and roles csharp

master/content event detection

home sitemap missing..please help

how to link to theme?

how to change style for staticmenuitem level 1

help!!!!! on page themes!

hide/show sitemap child accordingly to a querystring parameter

static menu items urls

accessing a htmlgenericcontrol on a masterpage from a contentpage

help with the treeview...

difficult to control the style of the menu in asp.net 2.0

hide tabs from menu control on master page

wizard finish cancel not working

positioning issues

asp.net menu control 2.0 is a problem

menu control expand items

masterpage that pulls content from secondlevel directory off of root traps you in that directory

wierd populatenodesfromclient behavior

rendering problem with rjs popcalendar & masterpage

treeview collapse accessibility problems

   
  Privacy | Contact Us
All Times Are GMT