|
Do you know if its possible to rewrite the following code for a textbox in a datagrid to a drop down list
<asp:TextBox runat="server" ID="txtUpdate" Text='<%#convert.tostring(databinder.eval(container.dataitem,"groups")) %>'></asp:TextBox>
<EditItemTemplate>
<asp:DropDownList runat=server id="listUpdate">
<asp:ListItem Value="Admin">Admin</asp:ListItem>
<asp:ListItem Value ="User" >User</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
i don't know where i can set the databinder field, so that i can send it to my update statement
|
|
|
|
|
You need to bind it in the ItemDataBound avent of the databgrid.
if your table has a column called "AccessLevel" with (enum?) values "Admin" or "User", then you could use something like the below in this (ItemDataBound) event:
If e.Item.ItemType = ListItemType.EditItem Then
Dim lstUpdate As ListBox = e.Item.FindControl("lstUpdate")
Dim dr As DataRow = e.Item.DataItem.Row, DataRowView
lstUpdate.Items.FindByValue(dr("AccessLevel")).Selected = True
End If
|
|
|
|
|
Previous posty is how you set it, of course, to the value it already has. You read it back and updaate the database in the UpdateCommand event of the datagrid, using:
Dim SelectedID As String = datGridID.DataKeys(e.Item.ItemIndex).ToString
to get teh row ID of teh row in question
Dim lstUpdate As DropdownList = e.Item.FindControl("lstUpdate")
to get the dropdown, then buidl your sql statemetn by it's SelectedValue property
(just realised I used Listbox in earlier post, not DropdownList so you'll need ot amend that)
|
|
|
|
|
HI Fred
I still can't get this bit of code to work
I have this so far
If e.Item.ItemType = ListItemType.EditItem Then
Dim lstUpdate As DropDownList = e.Item.FindControl("lstUpdate")
Dim dr As DataRow = e.Item.DataItem.row
lstUpdate.Items.FindByValue(dr("groups")).Selected = True
End If
I get this error message for "dim dr As DataRow = e.Item.DataItem.row"
Object variable or With block variable not set
You have said to put it as datagridview, but it doesn't seem to like that I am guessin it should be my datagrid variable that goes in here and it still doesn't work
|
|
|
|
|
hm.. we could probably run round forever on this - if you want to email your complete page (html and code-behind) I'll have a look at it for you... blank out your db connectionstring (esp if it's on a public server)
|
|
|
|
|
Heres my code here fred
<code>
Public Sub onEdit(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.EditCommand
dgPriv.EditItemIndex = e.Item.ItemIndex
bindGrid()
End Sub
Public Sub oncancel(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.CancelCommand
dgPriv.EditItemIndex = -1
bindGrid()
End Sub
Public Sub onUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.UpdateCommand
Dim err As New LiteralControl
If e.Item.ItemType = ListItemType.EditItem Then
Dim lstUpdate As DropDownList = e.Item.FindControl("lstUpdate")
Dim dr As DataRow = e.Item.DataItem
lstUpdate.Items.FindByValue(dr("groups")).Selected = True
End If
Dim SelectedID As String = dgPriv.DataKeys(e.Item.ItemIndex).ToString
Try
Dim cnString As String = "Server=;"
Dim cn As New MySqlConnection(cnString)
'Create mySql command string for passing query or SPROC(Stored Procedure)
Dim cmdString As New MySqlCommand
'Set Command to equal mySql connection, so can pass SQL query
cmdString.Connection = cn
'Set command string to equal SPROC
cmdString.CommandText = "sp_update"
'ONLY PLACE THIS IF SPROC, sets the command to a SPROC
cmdString.CommandType = CommandType.StoredProcedure
Dim param As MySqlParameter
param = cmdString.Parameters.Add("?p_userid", MySqlDbType.Int64)
param.Direction = ParameterDirection.Input
param.Value = dgPriv.DataKeys(e.Item.ItemIndex)
param = cmdString.Parameters.Add("?p_groups", MySqlDbType.VarChar)
param.Direction = ParameterDirection.Input
param.Value = SelectedID
cn.Open()
cmdString.ExecuteNonQuery()
cn.Close()
Catch ex As Exception
err.Text = ex.Message
MsgBox(ex.Message)
End Try
dgPriv.EditItemIndex = -1
bindGrid()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dgPriv" runat="server" BorderWidth="0"
CellPadding="4" Width="100%"
Font-Size="Smaller"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True"
HeaderStyle-BackColor="Navy"
HeaderStyle-ForeColor="White"
datakeyfield ="userId"
AlternatingItemStyle-BackColor="ActiveBorder"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField ="userId" HeaderText="User ID" ReadOnly="true"></asp:BoundColumn>
<asp:BoundColumn DataField ="username" HeaderText="User Name" ReadOnly="true"></asp:BoundColumn>
<asp:BoundColumn DataField ="groups" HeaderText="Privelages" ReadOnly="true"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Update Privelages">
<EditItemTemplate>
<asp:DropDownList runat=server id="listUpdate" DataMember='<%#convert.tostring(databinder.eval(container.dataitem,"groups")) %>' >
<asp:ListItem Value="Admin">Admin</asp:ListItem>
<asp:ListItem Value ="User" >User</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" EditText="Change Privelage" UpdateText="Change" CancelText ="cancel" >
</asp:EditCommandColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" />
<AlternatingItemStyle BackColor="ActiveBorder" />
<HeaderStyle BackColor="Navy" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
</asp:datagrid>></code>
|
|
|
|
|
hmm well I assume you've missed bits out... anyway, the immediate thing is that you ned to bind the lstUpdate control in the itemdatabounbd event - it's too late and no good trying to do it in the update event.
But in a way that's not vital - it just sets the dropdown to the value it already has in the database - useful but not critical.
For the update, all you need do is find the dropdown control and use it's selectedValue property...
btw, why are all your Sub's public?
Anyway, here is some amended bits
Private Sub dgPriv_ItemDataBound(ByVal source As Object, ByVal e As DataGridItemEventArgs) Handles dgPriv.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim lstUpdate As DropDownList = e.Item.FindControl("lstUpdate")
Dim dr As DataRow = e.Item.DataItem
lstUpdate.Items.FindByValue(dr("groups")).Selected = True
End If
End If
Public Sub onUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.UpdateCommand)
Dim err As New LiteralControl
' Dim SelectedID As Integer = dgPriv.DataKeys(e.Item.ItemIndex)
Dim lstUpdate As DropDownList = e.Item.FindControl("lstUpdate")
Try
' code here cut for space; you will nned to put it back!
Dim param As MySqlParameter
param = cmdString.Parameters.Add("?p_userid", MySqlDbType.Int64)
param.Direction = ParameterDirection.Input
param.Value = dgPriv.DataKeys(e.Item.ItemIndex) ' = SelectedID
param = cmdString.Parameters.Add("?p_groups", MySqlDbType.VarChar)
param.Direction = ParameterDirection.Input
param.Value = lstUpdate.SelectedValue
cn.Open()
cmdString.ExecuteNonQuery()
cn.Close()
Catch ex As Exception
err.Text = ex.Message
MsgBox(ex.Message)
End Try
dgPriv.EditItemIndex = -1
bindGrid()
End Sub
|
|
|
|
|
In my ASPX page I am uploading files to server. I use HTML file upload control by making it runat=server . This page is for uploading multiple files, means more that 20 file upload controls will be present in the form. When uploading one by one files, it is taking lot of time. So I thought of using threads.
My file upload controls are in Gridview. I started a loop and find upload controls. For each controls I started a thread and uploading will be done on that thread. My doubt is, if I redirect to some other page before upload finishes, will that threads still executing on server ? And will it finish the upload job ?
|
|
|
|
|
Yu can multithread this all you want. It won't make any difference in the time it takes to upload a file. The pipe carrying the data can't send any more than a single stream of bytes for any one source at a time, so it'll take just as long to do the upload. It's just that the pipe will carry a chunck of data from this file, then a chunk of data from the next, and another chuck from the next file, and so on and so on until all the chunks of all files it sent. The network pipe cannot carry 2 chunks of two files at the same time.
|
|
|
|
|
Hello!
Yesterday I installed IE7. after this I cant run any web-project in Visual Studio 2003 in debug mode (by F5) but in normal mode (by ctrl+5) all is ok.
I got a messge - "Verify that you are memebrof the Debugger Users group on the server".
I checked it and include ASPNET (ASP.NET Machine Account), IUSR_AB4 (Guest account of Iternet), IWAM_AB4 (account for IIS run),SQLDebugger and urban (my account in the machine) into that group but I still got an error.
I checked a configuratio of IE and add http://localhost into trusted connetcions. same error
I restarted PC - same error
btw - web projects from vs 2005 are working correct either by f5 and by ctrl+f5
what happened and what should I do?
thanx!!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
Try this
open Internet Information Server (Start Menu>Run>inetmgr)
select your Web application ,take properties, click on configuration button, then Debugging tab and enable it,
hope it may solve ur problem.
|
|
|
|
|
No. it did not solve my problem
I dont understnad - why it was happened after IE7 installing?
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
solved.. thanx to all.. ad to me and to google..
I add localhost to trusted zone set security settings for the trusted zone to "Automatic logon with current username and password"
http://msdn2.microsoft.com/en-us/library/Aa290100(VS.71).aspx
-- modified at 8:03 Saturday 21st July, 2007
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
Hi, I have a question. If I create a webservice that happens to have two threads for seperate tasks - when I use lock, I understand that the 1 thread will not run until the other finishes its task that is locked. My question then, does this lock per request, or for the entire application? I am just worried what would happen if 3 requests came in at the same time.
Thanks in advance!
|
|
|
|
|
When you lock it is for the entire application - but his initial assumption was incorrect, so it won't have as great an impact as he originally though.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
toticow wrote: when I use lock, I understand that the 1 thread will not run until the other finishes its task that is locked
Incorrect. It means that the second thread cannot enter any section that uses the same object for the lock. Both threads can continue running simultaneously even if one is inside a locked section.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Thank you for the answer.
|
|
|
|
|
Hi
I have a login session which runs out after 30 mins
If the user wants to use it again they will get redirected to a login screen
But i want to be able to send them back to the screen they where on previously
How would i get it to store the page address and get it to redirect back here?
Would it be another session which would send the page address back to the user login?
cheers boyindie
|
|
|
|
|
One Way is that you send the url as query string, same as the dot net does.
for ex:
in page Home.aspx, if session expired, redirect it to loginpage as
Response.Redirect("login.aspx?ReturnUrl=Home.aspx");
and after logging in successfull send the user to Home page as
Response.Redirect(Request.params["ReturnUrl"]);
you can set addiotional checks in login page like.
string ReturnUrl = "Default.aspx" ; // the default page if user comes directly to login page.
if(Request.params["ReturnUrl"] != null)
ReturnUrl = Reuest.Params["Returnurl"];
Response.Redirect(ReturnUrl);
you can also use Request.UrlReferrer method.
|
|
|
|
|
|
is there any query that list all the tables in the database?
Sonia Gupta
Soniagupta1@yahoo.co.in
Yahoo messengerId-soniagupta1
Love is Friendship and Friendship is Love....
|
|
|
|
|
SELECT *
FROM dbo.sysobjects
WHERE (xtype = 'u')
|
|
|
|
|
Navaneeth ,
it is giving error.
error is - cannot find the "c:\document and settings\abc\my documents\dbo.mdb"
My database is MS-Access
Sonia Gupta
Soniagupta1@yahoo.co.in
Yahoo messengerId-soniagupta1
Love is Friendship and Friendship is Love....
|
|
|
|
|
|
SELECT *
FROM information_schema.Tables
it worked for me so should work for u
|
|
|
|