Jump to content
Sign in to follow this  
startuga

[Resolvido] Gridview

Recommended Posts

startuga

Boas pessoal,

Necessito de alguma ajuda.

Tenho uma Gridview no form1 e uma DetailsView no form2, como é que posso proceder para selecionar uma Row na gridview do form1 e exibir a informação dessa row na DetailsView do form2 para fazer update(edit)?

Alguma ideia?

Share this post


Link to post
Share on other sites
ErasedGOD

Fazer a ligação entre as duas... tens ai o metodo: http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx

eu uso directo, fica um exemplo:

nomedagrid.DataSource = dadosameter;

nomedagrid.DataBind();

//Com um repeater

List<ListaDetailsview> source = fillListaDetailsview();

nomedagrid.DataSource = source;

if (source != null && source.Count > 0)

{

nomedagrid.DataBind();

}

}

já tens ai umas dicas :thumbsup:

Share this post


Link to post
Share on other sites
ErasedGOD

eu implemento assim:

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindGrid();

}

}

Depois o código irá depender de como tenhas isso... tens a detailsview listada?é dinâmica?

Share this post


Link to post
Share on other sites
startuga

Isto é o que tenho no código da DetailsView

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication1.WebForm2" %>
<!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></title>
   <style type="text/css">
    #form1
    {
	    height: 491px;
    }
   </style>
</head>
<body>
   <form id="form1" runat="server">
   <div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
	    ConnectionString="<%$ ConnectionStrings:MarketingConnectionString2 %>"
	    SelectCommand="SELECT CLUSTERS.AREA_ID, CLUSTERS.Cluster_Name, CLUSTERS.Cluster_ID, CLUSTERS.Cluster_ENABLE, AREAS.AREA_ID AS Expr1 FROM CLUSTERS INNER JOIN AREAS ON CLUSTERS.AREA_ID = AREAS.AREA_ID"
	    UpdateCommand="UPDATE CLUSTERS SET AREA_ID =, Cluster_Name =, Cluster_ID =, Cluster_ENABLE = FROM CLUSTERS INNER JOIN AREAS ON CLUSTERS.AREA_ID = AREAS.AREA_ID">
    </asp:SqlDataSource>

    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
	    DataSourceID="SqlDataSource1" DefaultMode="Edit" Height="50px" Width="125px">
	    <Fields>
		    <asp:BoundField DataField="AREA_ID" HeaderText="AREA_ID"
			    SortExpression="AREA_ID" />
		    <asp:BoundField DataField="Cluster_Name" HeaderText="Cluster_Name"
			    SortExpression="Cluster_Name" />
		    <asp:BoundField DataField="Cluster_ID" HeaderText="Cluster_ID"
			    SortExpression="Cluster_ID" />
		    <asp:CheckBoxField DataField="Cluster_ENABLE" HeaderText="Cluster_ENABLE"
			    SortExpression="Cluster_ENABLE" />
		    <asp:BoundField DataField="Expr1" HeaderText="Expr1" SortExpression="Expr1" />
		    <asp:CommandField ShowEditButton="True" />
	    </Fields>
    </asp:DetailsView>

   </div>

   </form>
</body>
</html>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.