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: 212 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:













"populateondemand can't be set to true on a node that already has children." not true

a guestion follow the driven site map provider

change menu dinamically

what is the right way to more than one menu in sitemap? thanks!

background-image disappearing in beta 2

accessing master page controls from content page

asp.net 2.0 menu expand clickable area

master page form breaking child pages nested divs scrollbars

image references on masterpages

need some help with menu

css and asp.net

make search in master page

can't seem to update my stylesheets

reference masterpage from vb class object

master page theme

how to override master page style with themes enabled

menu+sitemap+menuitem click event event

best practices

page name?

cannot show checkbox in treeview

add master page to an existing page

how can i reach a button in a template from aspx.cs to change its proberties?

link button on a master page

treeview control

asp.net 2.0 menu mouseover

trouble passing menuitemclick along

why i'm getting this error? is this something wrong

masterpage loading

disabling postback in a asp menu with vs2008 and net 3.5

dynamically load in stylesheets at runtime

nesting a classic asp page inside a asp.net masterpage

treeview toggle nodes

tree view question

alternative for the standard .net menu control

newbie - automatically size the content holder on a master page?

automatic <title> with sitemap

menu style

content pages created from database....

treeview performance limitations

theme general

asp:menu - arrow pushes centered menu text

treeview and securitytrimmingenabled

root link set to an image not text.

chang separator arrow in menu in asp tools ?

update to master pages causes system.outofmemoryexception error

navigation menu question.

alligning a grid view in master page

navigation permissions

dynamic menu using .sitemap file

some problems with master pages

   
  Privacy | Contact Us
All Times Are GMT