|
|
i didn't get, what i exactly need. I want dynamic sorting
|
|
|
|
|
I am using C# as base language to devlope a asp.net website. The problem is that I want to use SqlDataadapter but I find it to be disabled in the toolbox. I ve tried to genrate a dataadapter by dragging a table from Server explorer to Default.aspx form but instead of SQLDataAdapter it genrates a SqlDatasource and dataview. Can someone please tell me what I need to do to use a Sqldataadapter in asp.net?
|
|
|
|
|
raviroyx wrote: The problem is that I want to use SqlDataadapter but I find it to be disabled in the toolbox
Excellent - Being able to drag that from the toolbox to your page is the first stage in producing very badly designed code.
raviroyx wrote: Can someone please tell me what I need to do to use a Sqldataadapter in asp.net?
SqlDataAdapter da = new SqlDataAdapter();
See Also:
SqlDataAdapter Class[^] (MSDN)
|
|
|
|
|
I said I dragged a table from Server explorer to form not a dataadapter from toolbox.
|
|
|
|
|
Either way my basic message stands. Don't drag and drop data items from the toolbox or server explorer to your form. Learn how the database interaction actually works then create your own DAL (Data Access Layer) to do it properly. Putting data access on a form is very VERY bad design. Just don't do it. Period!
|
|
|
|
|
Are You using vs2005 or vs2003 ?
StonePit
|
|
|
|
|
Hi!
I am getting up to speed working with web development in vs 2005 and I'm missing a feature in the VS environment. When working in design mode with a page, I want to have easy access to create delegates for any event available in my custom server controls, but I can not find anything of the kind. (I also want easy navigation to the code once I've implemented it.) The events for any regular (predefined) web control are available as expected, but not the ones I define in my own controls.
I get the feeling I'm missing something in my code, since I can find no way to get the controls to appear in the Toolbox either. I've created the controls using Add new Item, choosing the Web User Control template.
Does anyone have any ideas as to what I might be doing wrong? Or this this a (undocumented) feature (read: bug) in the new development environment?
Carolina Berglund Consultant, systemdeveloper and architect.
|
|
|
|
|
|
Yeah, this is what I am missing, but the problem is I don't have the events symbol mentioned in point 2...
Carolina Berglund
Consultant, systemdeveloper and architect.
|
|
|
|
|
Are you viewing the web page in Design View or Source View?
|
|
|
|
|
It's in design view I miss this feature
|
|
|
|
|
Do you select the control in the Design view?
|
|
|
|
|
Yes...
I'm not noob on this, and I have already entered all code I need to make this [ie using the events I need] work, I just want to know why the user-friendly way to do it is unavailable for my custom controls. Any regular control in the framework has the events button in the Properties pane, so I'm sure there is nothing wrong with my installation or with the way I use the environment.
There must be something missing in the code, but I can't find any reference to what is needed to get a custom web control to display the events pane in design mode.
|
|
|
|
|
If it works for all the built-in controls, but your custom control, then I also think it may be down to your code. If you don't mind and cannot find the root cause, can you post it here, I'll have a stab at it.
|
|
|
|
|
Sure, no problem.
I've cleared out some of the code that references my business logic class, since you dont have access to it. This includes a public property for assigning an instance of my BL-class to the control, and this property shows up in the properties window in design mode when this control is included in a web page.
This is the source for one of my ascx pages:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EducationEdit.ascx.cs" Inherits="cv_EducationEdit" %>
<table width="600">
<tr>
<td align="right">
<asp:LinkButton ID="btnAddEducation" runat="server" Text="[Lägg till utbildning och kurser]" OnClick="btnAddEducation_Click"/>
</td>
</tr>
</table>
<asp:Panel ID="pnlEditEducation" runat="server" Visible="false">
<table width="600">
<tr>
<td>Typ</td><td><asp:DropDownList ID="ddlType" runat="server"/></td>
</tr>
<tr>
<td>Utbildning</td><td><asp:DropDownList ID="ddlName" runat="server"/></td><td><asp:TextBox ID="txtName" runat="server"/><asp:Button ID="btnNewName" runat="server" Text="Ny" OnClick="btnNewName_Click" CssClass="stdButton"/></td>
</tr>
<tr>
<td>Institut</td><td><asp:DropDownList ID="ddlEducator" runat="server"/></td><td><asp:TextBox ID="txtEducator" runat="server"/><asp:Button ID="btnNewPlace" runat="server" Text="Ny" OnClick="btnNewEducator_Click" /></td>
</tr>
<tr>
<td>Datum</td><td><asp:DropDownList ID="ddlStartYear" runat="server"/>-<asp:DropDownList ID="ddlStartMonth" runat="server"/> - <asp:DropDownList ID="ddlEndYear" runat="server"/>-<asp:DropDownList ID="ddlEndMonth" runat="server"/></td>
</tr>
<tr>
<td>Visa vid export</td><td>
<asp:CheckBox ID="ShowInFile" runat="server" /></td>
</tr>
<tr>
<td><asp:Button ID="btnSave" runat="server" Text="Spara" OnClick="btnSave_Click" CssClass="stdButton"/><asp:Button ID="btnCancel" runat="server" Text="Avbryt" OnClick="btnCancel_Click" CssClass="stdButton"/></td>
</tr>
</table>
</asp:Panel>
And this is the corresponding code-behind (.cs):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class cv_EducationEdit : System.Web.UI.UserControl {
public delegate void UpdateEventHandler();
public event UpdateEventHandler Update;
private const string PAGESESSION_EDUCATION = "pEducation";
/// <summary>
/// Fills the drop downs
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
pFillEditValues();
}
}
/// <summary>
/// Fires an update event to inform the parent control that the current item has been saved and updated.
/// Used for informing the parent control to update all lists with Technical Skills
/// </summary>
protected virtual void OnUpdate() {
if (Update != null) {
// Invokes the delegates.
Update();
}
}
/// <summary>
/// Fills the drop downs and text boxes with possible values
/// </summary>
private void pFillEditValues() {
//Code to fill drop down combos
}
/// <summary>
/// Adds a new name of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewName_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtName.Text, txtName.Text);
ddlName.Items.Add(li);
ddlName.SelectedIndex = -1;
li.Selected = true;
txtName.Text = "";
}
/// <summary>
/// Adds a new educator of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewEducator_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtEducator.Text, txtEducator.Text);
ddlEducator.Items.Add(li);
ddlEducator.SelectedIndex = -1;
li.Selected = true;
txtEducator.Text = "";
}
/// <summary>
/// Hides the new button and opens the control in edit mode with a new blank item
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAddEducation_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = true;
btnAddEducation.Visible = false;
}
/// <summary>
/// Saves the current item, hides the edit panel, shows the add button and fires an Update event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e) {
//Create or update my custom object
txtName.Text = "";
txtEducator.Text = "";
//Trigger event
OnUpdate();
pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
/// <summary>
/// Hides the edit panel and displays the add button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
}
And this is the code I use for including the control in a web page(aspx):
<div class="cvParagraph">
<uc4:EducationEdit ID="EducationEdit1" runat="server" OnUpdate="EducationEdit_Update" />
</div>
Thank you for taking your time with me!
Carolina Berglund
Consultant, systemdeveloper and architect.
|
|
|
|
|
Hi there,
Ahh web user control, historically VS 2003 does not support displaying the custom properties/events of a web user control .ascx in Properties windows and Intellisense is not provided in the Html view (now is the Source View in VS 2005). And when the VS 2005 comes out, there are a couple of improvoments like displaying the custom preperties in the Properties windows, and the Intellisens is also supported in the Html view. However, it still does not support adding the event handler for a web user control from the Properties windows. That being said, your choices are to add the handler in the Source view then manually add the source for the handler or you can add in code behind for example in the InitializeComponent method and have VS 2005 generate the method implementation.
|
|
|
|
|
|
hi!, there is a page, say, my.aspx. in this there is a .... block contains a function say func(). i want whenever my.aspx page loaded this function func() get executed on every post back.
|
|
|
|
|
You can call that javascript function on onload event of the body tag in the html section.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks! but i have to passed some values from code behind from to that java script function.
|
|
|
|
|
Hi,
u can use the following server side function.
if (!(this.IsStartupScriptRegistered("Startup")))
Page.RegisterStartupScript("StartUp","fun('"+ arg1 + "')");
|
|
|
|
|
exactly same way you can do as psamy said. also you can even write complete function in code behind itself.
Best Regards,
Apurva Kaushal
|
|
|
|
|
|
something like this you can use..:
string str = "<script language='javascript'>";<br />
str += "function Focu(){";<br />
str += "document.getElementById('TextBox3').focus();}<";<br />
str += "/";<br />
str += "script>";<br />
if(!IsStartupScriptRegistered("Test"))<br />
{<br />
Page.RegisterStartupScript("Test",str);<br />
}
Best Regards,
Apurva Kaushal
|
|
|
|