EdwardPeter
asked on
datagrid Controls(1),
Hi,
How can we query the value of the column number 1 when delete link was click using datagrid.
DirectCast(e.Item.Cells(1) .Controls( 1),TextBox ) <---------why do we need to place a 1 inside control to work?
How can we remove the 1 and still be able to query like so
DirectCast(e.Item.Cells(1) .Controls( 0),TextBox )
Kindly assist.
Thanks.
Sub manage_update( s As Object, e As DataGridCommandEventArgs)
Dim key As String = DataGrid1.DataKeys(e.Item. ItemIndex) .ToString( )
dim txtdatecoached1 As textbox = DirectCast(e.Item.Cells(1) .Controls( 1),TextBox ) <---------notice Controls(1)
End sub
How can we query the value of the column number 1 when delete link was click using datagrid.
DirectCast(e.Item.Cells(1)
How can we remove the 1 and still be able to query like so
DirectCast(e.Item.Cells(1)
Kindly assist.
Thanks.
Sub manage_update( s As Object, e As DataGridCommandEventArgs)
Dim key As String = DataGrid1.DataKeys(e.Item.
dim txtdatecoached1 As textbox = DirectCast(e.Item.Cells(1)
End sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Usually when delete link is clicked you do not want to grab value from TextBox... cause you dont want your Users to modify some number and then click delete link.. try get value using following line in your delete command:
Dim key As String = e.Item.Cells(1).Text
-tushar
Dim key As String = e.Item.Cells(1).Text
-tushar
ASKER
tusharashah,
no errors, it only showed "Deleted."
kindly assist how can we troubleshoot?
Thanks.
Sub manage_Delete(ByVal source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args)
Dim key As String = DataGrid1.DataKeys(e.Item. ItemIndex) .ToString( )
Dim VarTest As String = e.Item.Cells(1).Text <-----------------change done.
Dim con As New SqlConnection("....")
Dim cmd As SqlCommand = con.CreateCommand()
cmd.CommandType = CommandType.StoredProcedur e
cmd.CommandText = "SP_operator_score_delete"
cmd.Parameters.Add(New SqlParameter("@RETURN_VALU E", SqlDbType.Int, 4, ParameterDirection.ReturnV alue, False, CType(0, Byte), CType(0, Byte), "", DataRowVersion.Current, Nothing))
cmd.Parameters.Add("@opera toranalysi sid",SqlDb Type.int). Value = key
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds,"DataSetName")
label1.text=VarTest &" Deleted." <-------to display
cmd.dispose
cmd.parameters.clear
con.close
DataGrid1.CurrentPageIndex = 0
datagrid1.DataSource=Gener ateSource( ).DefaultV iew
datagrid1.DataBind()
End Sub
no errors, it only showed "Deleted."
kindly assist how can we troubleshoot?
Thanks.
Sub manage_Delete(ByVal source As Object, ByVal e As System.Web.UI.WebControls.
Dim key As String = DataGrid1.DataKeys(e.Item.
Dim VarTest As String = e.Item.Cells(1).Text <-----------------change done.
Dim con As New SqlConnection("....")
Dim cmd As SqlCommand = con.CreateCommand()
cmd.CommandType = CommandType.StoredProcedur
cmd.CommandText = "SP_operator_score_delete"
cmd.Parameters.Add(New SqlParameter("@RETURN_VALU
cmd.Parameters.Add("@opera
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds,"DataSetName")
label1.text=VarTest &" Deleted." <-------to display
cmd.dispose
cmd.parameters.clear
con.close
DataGrid1.CurrentPageIndex
datagrid1.DataSource=Gener
datagrid1.DataBind()
End Sub
How do you have 1st Column on your DataGrid? is it BoundColumn or Template Column? Paste the code of DataGrid from ASPX in here...
Also change following line: ( you dont need SqldataAdapter and DataSet just to run a query )
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds,"DataSetName")
Replace with: cmd.ExecuteNonQuery()
-tushar
Also change following line: ( you dont need SqldataAdapter and DataSet just to run a query )
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds,"DataSetName")
Replace with: cmd.ExecuteNonQuery()
-tushar
ASKER
tusharashah,
is it okay if you could kindly guide me both ways?
one with bound and another with template?
Thanks so much.
is it okay if you could kindly guide me both ways?
one with bound and another with template?
Thanks so much.
If you have that particular column as BoundColumn then you would use: e.Item.Cells(1).Text
& if you have that particular column as TemplateColumn then you'll have to find the control that you have inside your template column:
Lets say you have Label inside then you would use it liek this:
Dim key As String = CType(e.Item.Cells(1).Find Control("L abel1"), Label).Text
Also, remember that Column Number in DataGrid starts from 0 not 1. So, if in case the value that you want is in 1st Column then you'd use: e.Item.Cells(0).text
-tushar
& if you have that particular column as TemplateColumn then you'll have to find the control that you have inside your template column:
Lets say you have Label inside then you would use it liek this:
Dim key As String = CType(e.Item.Cells(1).Find
Also, remember that Column Number in DataGrid starts from 0 not 1. So, if in case the value that you want is in 1st Column then you'd use: e.Item.Cells(0).text
-tushar
ASKER
tusharashah,
Sad to say no error messages and the label1 only displayed "Deleted." without the callnumber column.
kindly assist.
Thanks.
Sub manage_Delete(ByVal source As Object, ByVal e As System.Web.UI.WebControls. DataGridCo mmandEvent Args)
Dim key As String = DataGrid1.DataKeys(e.Item. ItemIndex) .ToString( )
Dim key2 As String = e.Item.Cells(1).Text
<asp:DataGrid id="DataGrid1" runat="server" Font-Size="xx-small" Font-Names="Verdana" datakeyfield="operatoranal ysisid" OnSortCommand="Sort_Grid" AllowSorting="True" GridLines="Horizontal" OnItemDataBound="manage_It emDataBoun d" OnEditCommand="manage_edit " OnCancelCommand="manage_ca ncel_edit" OnUpdateCommand="manage_up date" OnDeleteCommand="manage_de lete" PageSize="40" AllowPaging="True" onPageIndexChanged="pageGr id" CellPadding="4" AutoGenerateColumns="False ">
<EditItemStyle wrap="False"></EditItemSty le>
<ItemStyle wrap="False"></ItemStyle>
<HeaderStyle forecolor="Blue"></HeaderS tyle>
<Columns>
<asp:BoundColumn DataField="CallNumber" SortExpression="CallNumber " ReadOnly="True" HeaderText="Call#">
<HeaderStyle forecolor="Blue"></HeaderS tyle>
<ItemStyle horizontalalign="Center">< /ItemStyle >
</asp:BoundColumn>
Sad to say no error messages and the label1 only displayed "Deleted." without the callnumber column.
kindly assist.
Thanks.
Sub manage_Delete(ByVal source As Object, ByVal e As System.Web.UI.WebControls.
Dim key As String = DataGrid1.DataKeys(e.Item.
Dim key2 As String = e.Item.Cells(1).Text
<asp:DataGrid id="DataGrid1" runat="server" Font-Size="xx-small" Font-Names="Verdana" datakeyfield="operatoranal
<EditItemStyle wrap="False"></EditItemSty
<ItemStyle wrap="False"></ItemStyle>
<HeaderStyle forecolor="Blue"></HeaderS
<Columns>
<asp:BoundColumn DataField="CallNumber" SortExpression="CallNumber
<HeaderStyle forecolor="Blue"></HeaderS
<ItemStyle horizontalalign="Center"><
</asp:BoundColumn>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So, to refer this control you have to specify the 1 and it means you're refering Item's cell 1's control 1.
But, if you're facing any sort of problem b'coz of saying 1 here ... post it here, we will try to give you solution.
Cheers!!