someone know why???
(i already run aspnet_regiis.exe)Go towww.azamsharp.cjb.net
then go to Articles and select DataGrid common operations. I am sure you will find something interesting over there.
im sorry...but i didnt understand how can it help me?
the code is written and working great on another computer-but not on mine...
Are u trying to use edit/delete functionality within a datagrid? can u elaborate on what the problem is?
Edited by SomeNewKid. Please post code between<code> and</code> tags.
this is the code- again:this code working great on another computer-but in my computer the edit/delete/add doesnt work-its only show the recordes from the database-but when i click on one of this command - there is no response...why?
<%@. Page Language="VB" debug=true%>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.OleDb" %
<script runat="server">
'declare connection
dim Conn as new OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Reality\DATA.mdb")sub Page_Load(obj as Object, e as EventArgs)
if Not Page.IsPostBack then
FillDataGrid()
end if
end subsub Submit(obj as object, e as eventargs)
'insert new data
dim i, j as integer
dim params(1) as string
dim strText as string
dim blnGo as boolean = truej = 0
for i = 0 to AddPanel.Controls.Count - 1
if AddPanel.controls(i).GetType Is GetType(TextBox) then
strText = Ctype(AddPanel.Controls(i), TextBox).Text
if strText <> "" then
params(j) = strText
else
blnGo = false
'lblMessage.Text = lblMessage.Text & "You forgot to enter " & _
' "a value for " & AddPanel.Controls(i).ID & "<p>"
lblMessage.Text = "?? ?? ?"
lblMessage.Style("ForeColor") = "Red"
end if
j = j + 1
end if
nextif not blnGo then
exit sub
end ifdim strSQL as string = "INSERT INTO Cities " & _
"(CityDesc) VALUES (" & _
"'" & params(0) & "')"ExecuteStatement(strSQL)
FillDataGrid()
end sub
sub dgData_Edit(obj as object, e as DataGridCommandEventArgs)
FillDataGrid(e.Item.ItemIndex)
end subsub dgData_Delete(obj as object, e as DataGridCommandEventArgs)
dim num as string=Ctype(e.Item.Cells(0).Controls(1),Label).Text
dim strSQL as string = "DELETE FROM Cities " & _
"WHERE CityId = " & numExecuteStatement(strSQL)
FillDataGrid()
end sub
sub dgData_Update(obj as object, e as DataGridCommandEventArgs)
if UpdateDataStore(e) then
FillDataGrid(-1)
end if
end subsub dgData_Cancel(obj as object, e as DataGridCommandEventArgs)
FillDataGrid(-1)
end subsub dgData_PageIndexChanged(obj as Object, e as DataGridPageChangedEventArgs)
dgData.DataBind()
end subfunction UpdateDataStore(e as DataGridCommandEventArgs) _
as booleandim i,j as integer
dim params(1) as string
dim strText as string
dim blnGo as boolean = truej = 0
' for i = 1 to e.Item.Cells.Count - 2
strText = Ctype(e.Item.Cells(3).Controls(0), TextBox).Text
if strText <> "" then
params(0) = strText
' j = j + 1
else
blnGo = false
'lblMessage.Text = lblMessage.Text & "You forgot to enter " & _
' "a value<p>"
lblMessage.Text = "?? ?? ?"
end if
' nextif not blnGo then
return false
exit function
end ifdim strSQL as string = "UPDATE Cities SET " & _
"CityDesc = '" & params(0) & "'" & _
" WHERE CityID = " & Ctype(e.Item.Cells(0).Controls(1), Label).textExecuteStatement(strSQL)
return blnGo
end functionsub FillDataGrid(Optional EditIndex as integer=-1)
'open connection
dim objCmd as new OleDbCommand _
("SELECT * FROM Cities ORDER BY CityDesc ASC", Conn)
dim objReader as OleDbDataReadertry
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader()
catch ex as Exception
lblMessage.Text = "Error retrieving from the database. Please" & _
" make sure all values are correctly input"
end trydgData.DataSource = objReader
if not EditIndex.Equals(Nothing) then
dgData.EditItemIndex = EditIndex
end ifdgData.DataBind()
objReader.Close
objCmd.Connection.Close()
tbCityName.text=""
lblMessage.Text=""end sub
function ExecuteStatement(strSQL)
dim objCmd as new OleDbCommand(strSQL, Conn)try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
catch ex as Exception
lblMessage.Text = "??? ?? ?? ???.? ?? ?? ?? ?? ???"
end tryobjCmd.Connection.Close()
end function
</script
<html>
<head>
<title>??</title>
</head>
<body style="FONT-WEIGHT: normal; FONT-SIZE: small; COLOR: black; FONT-STYLE: normal; FONT-FAMILY: Arial, Aharoni; BACKGROUND-COLOR: #ccccff; FONT-VARIANT: normal"
bgColor="#ffff99">
<DIV align="center">
<font size="4">?? ??</font
<form runat="server" >
<asp:DataGrid id="dgData" runat="server"
BorderColor="black" GridLines="Vertical" align=center
cellpadding="4" cellspacing="0" width="40%"
AutoGenerateColumns="False"
OnDeleteCommand="dgData_Delete"
OnEditCommand="dgData_Edit"
OnCancelCommand="dgData_Cancel"
OnUpdateCommand="dgData_Update"
OnPageIndexChanged="dgData_PageIndexChanged"
<Columns>
<asp:TemplateColumn visible=false>
<ItemTemplate>
<asp:Label id="Name" runat="server" visible=false
Text='<%# Container.DataItem("CityID") %>' />
</ItemTemplate>
</asp:TemplateColumn
<asp:ButtonColumn text="? ???"
CommandName="delete" />
<asp:EditCommandColumn
EditText="...??"
CancelText="?"
UpdateText="??" />
<asp:BoundColumn DataField="CityDesc" /
</Columns>
</asp:DataGrid><p
<asp:Panel id="AddPanel" runat="server">
<table align=center>
<tr>
<td colspan="2" valign="top" align="right">
<asp:Button id="btSubmit" runat="server"
text="??"
OnClick="Submit" />
</td
<td width="100" valign="top">
<asp:TextBox id="tbCityName" runat="server" />
</td>
<td width="50" valign="top">
:?? ?
</td
</tr>
<tr>
<td colspan=4><asp:Label id="lblMessage" runat="server" /></td>
</tr>
</table
</asp:Panel>
</form
</body></html>
please help!!!!!!!!!!1
what could be the problem??
maybe it something to do with properties?because i know that code is working...
Make sure that DataGrid events are attached to the required methods.
Right click on the dataGrid and select the "Lightening Sign" to view all events generated by datagrid and if those all are blank assign them to the appropriate methods.
yes- all DataGrid events are attached to the required methods.
so what could be the problem-maybe permission,IIS?
HI,
In
function ExecuteStatement(strSQL)dim objCmd as new OleDbCommand(strSQL, Conn)
i dont see you specifying CommandType.
Also in FillDataGrid method try to use DataSet instead of DataReader since in Distributing Computing DataSet is more reliable.
About Permission check and see if the user ( which might be ASPUSER ) has permissions to execute delete Queries or not.
In the link below check to see how delete operation is being done:
http://asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=609583
hi,
Add this in ur EditCommandColumn
</code>
<asp:EditCommandColumn ButtonType="LinkButton" ></asp:EditCommandColumn> </code
and see whether the edit link button have something changed.
if this work, ur update command will still cant work.
Solve it one by one
Cheers
life's Ng
hi-life's Ng ...
well its still dont work...do u think the problem its in the code?maybe something else?
Thanks
Super weird... For me, the below code enable me to at least see the changes(Cancel And Update text come up)...
sub dgData_Edit (Sender as object,e as DataGridCommandEventArgs)
FillDataGrid(e.Item.ItemIndex)
end sub<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="EDIT" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
ur case.... Mind if u try The code above? Sorry cant help u much.
Where did u get this codes from? Sams Teach yourself in 21 days? if u can get this book, i believe it helps alot for u to understand the codes.
I was tried this before and it's worked.(actually, after 1week+ of strugle to get it work)
If u want my full codes for reference, kindly let me know.
Cheers
life's Ng
Sorry, left out the filldatagrid event
sub FillDataGrid(Optional EditIndex as integer=-1)
dim dbtxt as string="OnShow"
dim objCmd as new OleDbCommand("select * from Personnel Where DbShow= '" & dbtxt &"' ", Conn)
dim objReader as OleDbDataReadertry
objCmd.Connection.Open()
objReader= objCmd.ExecuteReader()
catch ex as Exception
lblmessage.Text=" error retrieving from database."
end trydgData.DataSource=objReader
if not EditIndex.Equals(Nothing) then
dgData.EditItemIndex = EditIndex
end ifdgData.DataBind()
objReader.Close
objCmd.Connection.Close()
end sub
hi-
well i tried all this options-but no change!!!!:((((
i really dont know what to do-part of this code is from asp.net Chris Payne.
i still think that the problem is not in the code..:((((((((((((((((((
where i can i see this permissions?in the wwwrot properties?
0 comments:
Post a Comment