sqldatasourse and gridview

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

sqldatasourse and gridview

 
0
  #1
Mar 3rd, 2008
hii,,guys,,i m using asp.net2005 and sql server 2005...in my page i have used gridview and sql datasource,i m able to edit,update and delete the records,,the problem is tht for 1 column i would lik to use a dropdown list instead of textbox when i am in edit or update mode,,,heres is my code,,need help,,thnks in advance
  1. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sme_trackerConnectionString %>"
  2. SelectCommand="SELECT SME_Master.SME_Id, SME_Master.FirstName, SME_Master.LastName, SME_Master.Agency_id, SME_Master.Email, SME_Master.Address, SME_Master.Phone, SME_Master.Mobile, SME_Master.Fax, SME_Master.TimeZone_Id, SME_Master.Experience, SME_Master.City, SME_Master.State, SME_Master.Status, SME_Master.Level_Of_Exam, SME_Master.Other_Comments, SME_Master.Certificate, SME_Master.Expertise, Agency_Master.Agency_Name, SME_Master.Type_of_SME FROM SME_Master LEFT OUTER JOIN Agency_Master ON SME_Master.Agency_id = Agency_Master.Agency_Id"
  3. OnSelected="SqlDataSource1_Selected" InsertCommand="INSERT INTO [SME_Master] ([SME_Id], [FirstName], [LastName], [Type_of_SME], [Agency_id], [Email], [Address], [Phone], [Mobile], [Fax], [TimeZone_Id], [Experience], [City], [State], [Status], [Level_Of_Exam], [Other_Comments], [Certificate], [Expertise]) VALUES (@SME_Id, @FirstName, @LastName, @Type_of_SME, @Agency_id, @Email, @Address, @Phone, @Mobile, @Fax, @TimeZone_Id, @Experience, @City, @State, @Status, @Level_Of_Exam, @Other_Comments, @Certificate, @Expertise)" OldValuesParameterFormatString="original_{0}"
  4. UpdateCommand="UPDATE SME_Master SET FirstName = @FirstName, LastName = @LastName, Type_of_SME = @Type_of_SME, Email = @Email, Address = @Address, Phone = @Phone, Mobile = @Mobile, Fax = @Fax, Experience = @Experience, City = @City, State = @State, Agency_Master.Agency_Name = @Agency_Name FROM SME_Master INNER JOIN Agency_Master ON SME_Master.Agency_id = Agency_Master.Agency_Id WHERE (SME_Master.SME_Id = @original_SME_Id)"
  5. DeleteCommand="DELETE FROM SME_Master where SME_Id=@original_SME_Id"
  6. >
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: sqldatasourse and gridview

 
0
  #2
Mar 3rd, 2008
If i were you, i would use the grid view for selecting and use formview for updating. Formview is more flexible. You can insert dropdownlist to its edititemtemplate, read the entry in my blog http://www.daniweb.com/blogs/entry2043.html
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: sqldatasourse and gridview

 
0
  #3
Mar 4th, 2008
Originally Posted by serkansendur View Post
If i were you, i would use the grid view for selecting and use formview for updating. Formview is more flexible. You can insert dropdownlist to its edititemtemplate, read the entry in my blog http://www.daniweb.com/blogs/entry2043.html
hi,,,hey ur blog is really really nice,,,but now it wil b difficult for me to change all,,well i have managed to get the dropdown list instead of the textfield in edit mode,,,can u tell me how to update two table at the same time,coz the dropdown list column is frm another table and the other columns are from another table,,,,also how to make dropdown list to show the default value in edit mode,,,it was thr in ur blog bt i was not able to make it out clearly,,,heres is my code for the update command,,,,here agency_name is from another table and the rest of the columns are from diff table:::::here i m not able to update agency_name,,i hav done ths thr sqldatasource
  1. UPDATE SME_Master SET FirstName = @FirstName, LastName = @LastName, Type_of_SME = @Type_of_SME, Email = @Email, Address = @Address, Phone = @Phone, Mobile = @Mobile, Fax = @Fax, Experience = @Experience, City = @City, State = @State FROM SME_Master INNER JOIN Agency_Master ON SME_Master.Agency_id = Agency_Master.Agency_Id WHERE (SME_Master.SME_Id = @original_SME_Id)
thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: sqldatasourse and gridview

 
0
  #4
Mar 4th, 2008
welll now thrs a small change,,,,forget updating two tables,,,,sorry for tht,,what i m thinkin of is tht on updating the agency name(which is in the Agency_Master table),,,the particular agency_id (which is in SME_Master table)should change,,,in short i am updating the Agency_id,,,,,,,coz it is far more sensible to change the id on selecting the agency name,,,but the other prob still remains the same,,in edit mode the dropdown list should display the default value which is different for diff rows...how can i do tht..pls reply asap..thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: sqldatasourse and gridview

 
0
  #5
Mar 4th, 2008
First you need to set the gridview's autogeneratecolumns property to false then create template fileds under the columns section of the gridview :
<Columns>
<asp:TemplateField>
<ItemTemplate>
your normal controls go here
</ItemTemplate>
<EditItemTemplate>
your dropdown goes here
</EditItemTemplate>
</asp:TemplateField>
Last edited by serkan sendur; Mar 4th, 2008 at 6:45 am.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: sqldatasourse and gridview

 
0
  #6
Mar 5th, 2008
Originally Posted by serkansendur View Post
First you need to set the gridview's autogeneratecolumns property to false then create template fileds under the columns section of the gridview :
<Columns>
<asp:TemplateField>
<ItemTemplate>
your normal controls go here
</ItemTemplate>
<EditItemTemplate>
your dropdown goes here
</EditItemTemplate>
</asp:TemplateField>
whts next,,,,,boss can u giv ne idea how to display a confirmation box for delete,,coz now if i press delete frm gridview it deletes the record directly,,i just want to confirm the user whether he wants to delete or not......
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 20
Reputation: ravichandra is an unknown quantity at this point 
Solved Threads: 5
ravichandra ravichandra is offline Offline
Newbie Poster

Re: sqldatasourse and gridview

 
0
  #7
Mar 5th, 2008
Try this:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Page.RegisterClientScriptBlock("KEY", "<script language='javascript'>" + "confirm('Do you want to delete?')" + "</script>");
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: sqldatasourse and gridview

 
0
  #8
Mar 5th, 2008
Originally Posted by ravichandra View Post
Try this:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Page.RegisterClientScriptBlock("KEY", "<script language='javascript'>" + "confirm('Do you want to delete?')" + "</script>");
}
thnks ravi,,its done,,thnks
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: sqldatasourse and gridview

 
0
  #9
Mar 5th, 2008
Originally Posted by serkansendur View Post
First you need to set the gridview's autogeneratecolumns property to false then create template fileds under the columns section of the gridview :
<Columns>
<asp:TemplateField>
<ItemTemplate>
your normal controls go here
</ItemTemplate>
<EditItemTemplate>
your dropdown goes here
</EditItemTemplate>
</asp:TemplateField>
boss,,,u have helped me a lot,,coz of u and also othr ppl i am very near to complete my project,,neways 1 mor doubt....i have a gridview aand sql datasource,,,in edit mode i have put a dropdown list for agency_name column,,,wht i want is whn in edit mode,,the dropdown list should display its old value for that particular row,,now wht is happnin is tht if i click on edit of any row,the dropdown list shows 1st value,,hopw u got wht i m tryin 2 say,,
need ur help,,thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: sqldatasourse and gridview

 
0
  #10
Mar 5th, 2008
ok jonny i will help you but i am at office now, i must get home to answer your question. To provide you a step by step process i need to create a project for testing, i can not do that at the moment. Wait until i get home.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC