Sample Code: Using DetailsView in Whidbey

The Datagrid/DataList/Repeater control in ASP.NET had provided the flexibility and ease to show the data in a formatted manner. However sometimes the requirement is to flip the data from conventional horizontal layout to vertical layout and page a single record per page

This is possible using Datalist/Repeater/Datagrid but requires some amount of code (basically its not as easy as drag and drop and setting certain properties).

Some of my samples based on this requirement were as follows:

Building a Navigation System in ASP.NET

Use ViewState to display one record per page and also navigate

DetailsView control in Whidbey is one of the controls which can be used to give this kind of layout without any extra coding required

The code is as below

<asp:detailsview id="Detailsview1" runat="server" datasourceid ="Sqldatasource1" Allowpaging="true">

</asp:detailsview>

<asp:sqldatasource id="Sqldatasource1" runat="server"

selectcommand = "Select * from Employees"

selectcommand = "Select * from Employees"

connectionstring="Server=localhost;uid=sa;password=;database=northwind">

connectionstring="Server=localhost;uid=sa;password=;database=northwind">

</asp:sqldatasource>

Simple isnt it!!!! :-)

Simple isnt it!!!! :-)

</asp:detailsview>

<asp:sqldatasource id="Sqldatasource1" runat="server"

selectcommand = "Select * from Employees"

selectcommand = "Select * from Employees"

connectionstring="Server=localhost;uid=sa;password=;database=northwind">

connectionstring="Server=localhost;uid=sa;password=;database=northwind">

</asp:sqldatasource>

Simple isnt it!!!! :-)

Simple isnt it!!!! :-)

7 Comments

  • Simple indeed, who would want to bother to set password to system administrator user for their databases... Let alone run under a restricted security context, when running as the almighty sa with no password is so easy ;)



    As for the control itself - I have to repeat what I keep saying - if it's simple it's not going to be any good. I don't seem to have much control over what's rendered, and while I understand that most mouse programmers don't care, it's nice to be able to control what's shown to the user, maybe logically group the data, show it as either a table or a list, be able to set styles and so on...

  • Hi

    Iam using detailsview control

    want to add dropdownlist &amp; textarea into

    rowfield using template

    Please tell me how to do it



    Thanks

  • You can write code as follows

    &lt;asp:detailsview id=&quot;DetailsView1&quot; autogeneraterows =false datasourceid =&quot;Sqldatasource1&quot; runat=&quot;server&quot;&gt;

    &lt;rowfields&gt;

    &lt;asp:templatefield &gt;

    &lt;itemtemplate &gt;



    &lt;asp:textbox id=&quot;txt&quot; runat =server textmode =multiLine text=&lt;%#DataBinder.Eval(Container.DataItem, &quot;notes&quot;)%&gt; &gt;



    &lt;/asp:textbox&gt;

    &lt;/itemtemplate&gt;

    &lt;/asp:templatefield&gt;

    &lt;/rowfields&gt;

    &lt;/asp:detailsview&gt;

  • hi

    I am using Gridview and DetailsView controls.I want to show hyperlink for each word(separated by ',') in single column of GridView and display related details in DetailsView when click on any link item.

    How can I do it?



    Thanks.

  • Hi

    I'm using Detailsview and i'm trying to insert a dropdownlist. I actually did it using a template (thanks for the previous posts) but it seems it doesn't work just like a boundfield. I mean, the selected value in the dropdownlist is not set according to the datasource. In fact, i don't see any way to link the template field to a datasource field.

    Do you think i'm missing something? or maybe it simply doesn't work llike that....

    thanks in advance.....

  • Hi,

    How can I handle events of ListBox, added in Detailsview templatefield using c#,

    e.g. I want to handle SelectedIndexChanged for listbox.



    Thankx,

    Regards,

    Sachin

  • Hi,

    I want to confirm whether user realy wants to delete the current row from detilsview, and

    take action according to his click on YES/NO button.

    How can I do this using C#.

    Thankx.















































































































































































































































































































































































































































































































































































































































































































































































































































































Comments have been disabled for this content.