Hi, I'm want to pass an id to a gridview that contains a Select link. Once I select a row, that rows ID would return/replace the one passed. I think I've seen this done before but I can't find an example at this time. Please send a link or example if you
have one handy. Thx.
You can just use HyperLink to bind to a ID to generate the url link in the GridView, and then when someone clicks that, it will guide him/her to somewhere else and in that page please use Request.QueryString to accept the value and fetch or query what you
need.
Now that link takes the user to a custom page with a list of convents to choose from. Each row has a Select link. I'm now trying to figure out how to use the ExecuteStoreCommand to replace the ConventID in the Residence table with the ConventID selected from the list. (It's important that I use a list versus a dropdownlist so the user can view the entire address). I'm unclear on the connectionString - why it doesn't seem to recgonize my code.
sistersDBEntities se = new sistersDBEntities();
EntityConnection econn = (EntityConnection)se.Connection;
SqlConnection sconn = (SqlConnection)econn.StoreConnection;
protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
// Retrieve ConventID from the appropriate cell.
String selectedConventID = GridView1.SelectedRow.Cells[1].Text;
String sisID = Request.QueryString["SisterID"];
Message.Text = "Convent ID: " + selectedConventID;
Message2.Text = "Sister ID: " + sisID;
SqlCommand cmd = new SqlCommand("select CategoryName from Categories", conn);
se.ExecuteStoreCommand("UPDATE Convent SET ConventID = selectedConventID WHERE SisterID = sisID");
se.SaveChanges();
}
I tried this approach but I'm getting an error....
public class SharedObjectContext
{
private readonly sistersDBEntities context;
#region Singleton Pattern
// Static members are lazily initialized.
// .NET guarantees thread safety for static initialization.
private static readonly SharedObjectContext instance = new SharedObjectContext();
// Make the constructor private to hide it.
// This class adheres to the singleton pattern.
private SharedObjectContext()
{
// Create the ObjectContext.
context = new sistersDBEntities();
}
// Return the single instance of the ClientSessionManager type.
public static SharedObjectContext Instance
{
get
{
return instance;
}
}
#endregion
public sistersDBEntities Context
{
get
{
return context;
}
}
}
protected void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
{
// Retrieve ConventID from the appropriate cell.
String selectedConventID = GridView1.SelectedRow.Cells[1].Text;
String sisID = Request.QueryString["SisterID"];
Message.Text = "Convent ID: " + selectedConventID;
Message2.Text = "Sister ID: " + sisID;
sistersDBEntities context = SharedObjectContext.Instance.Context;
context.ExecuteStoreCommand("UPDATE Convent SET ConventID = selectedConventID WHERE SisterID = sisID");
context.SaveChanges();
}
Compiler Error Message: CS1061: 'ASP.dynamicdata_custompages_convent_conventselectlist_aspx' does not contain a definition for 'DataSource_Selected' and no extension method 'DataSource_Selected' accepting a first argument of type 'ASP.dynamicdata_custompages_convent_conventselectlist_aspx' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 64: <asp:label id="Message2" forecolor="Red" runat="server"/><br />
Line 65:
Line 66: <asp:EntityDataSource ID="GridDataSource" runat="server"
Line 67: OnSelected="DataSource_Selected" Include="Convent"
Line 68: ConnectionString="name=sistersDBEntities"
Source File: c:\inetpub\archivesDB\DynamicData\CustomPages\Convent\ConventSelectList.aspx Line: 66
I think this approach is messing up the EntityDataSource.
protected void FilterByConvent(object sender, CustomExpressionEventArgs e)
{
e.Query = from p in e.Query.Cast<Residence>()
where p.ConventID == (??? CONVENT ID PARAMETER ???)
select p;
}
Member
17 Points
90 Posts
passing id to Gridview
Sep 19, 2012 12:32 PM|jjfrick|LINK
Hi, I'm want to pass an id to a gridview that contains a Select link. Once I select a row, that rows ID would return/replace the one passed. I think I've seen this done before but I can't find an example at this time. Please send a link or example if you have one handy. Thx.
Contributor
3829 Points
1281 Posts
Re: passing id to Gridview
Sep 20, 2012 03:09 AM|matifnadeem|LINK
Hi
Follow the post
http://go4answers.webhost4life.com/Example/passing-id-hyperlink-gridview-90573.aspx
All-Star
94130 Points
18109 Posts
Re: passing id to Gridview
Sep 20, 2012 09:46 PM|Decker Dong - MSFT|LINK
Hello:)
You can just use HyperLink to bind to a ID to generate the url link in the GridView, and then when someone clicks that, it will guide him/her to somewhere else and in that page please use Request.QueryString to accept the value and fetch or query what you need.
To change the NavigateUrl:
NavigateUrl='<%# Eval("SomeIDfield", "xxx.aspx?id={0}"%>
Member
17 Points
90 Posts
Re: passing id to Gridview
Sep 21, 2012 08:37 AM|jjfrick|LINK
Thanks DD,
Here's how I solved my first issue...
Now that link takes the user to a custom page with a list of convents to choose from. Each row has a Select link. I'm now trying to figure out how to use the ExecuteStoreCommand to replace the ConventID in the Residence table with the ConventID selected from the list. (It's important that I use a list versus a dropdownlist so the user can view the entire address). I'm unclear on the connectionString - why it doesn't seem to recgonize my code.
Member
17 Points
90 Posts
Re: passing id to Gridview
Sep 21, 2012 09:41 AM|jjfrick|LINK
After reading this article: http://cgeers.com/2009/02/21/entity-framework-objectcontext/
I tried this approach but I'm getting an error....
I think this approach is messing up the EntityDataSource.
Member
17 Points
90 Posts
Re: passing id to Gridview
Sep 21, 2012 10:41 AM|jjfrick|LINK
I think I will just use a SPROC for this last step.
Contributor
2168 Points
905 Posts
Re: passing id to Gridview
Oct 08, 2012 09:16 AM|kaushikmaheta|LINK
use button then
commandargument='<%#Eval("your id field name")%>
Remember to click Mark as Answer on the post that helps to others.
Member
17 Points
90 Posts
Re: passing id to Gridview
Oct 08, 2012 10:11 AM|jjfrick|LINK
I think I have found a solution to my problem using QueryExtender - CustomExpression....
here's the gridview with QueryExtender:
and code behind:
My URL looks like this:
http://webapps/archives/Residence/ListDetails.aspx?ConventID=4232&SisterID=1115
How do I retrieve the ConventID parameter I'm passing?
Member
17 Points
90 Posts
Re: passing id to Gridview
Oct 08, 2012 12:46 PM|jjfrick|LINK
Here we go, this works....