Monday, July 25, 2005

DataGrid ItemCommand not firing

# re: DataGrid Paging Events not firing 7/25/2005 3:10 PM Moojjoo
Well everyone... Thank you. I read everybody's response and everyone helped out. My problem was with the ItemCommand Event not firing..

Solutions... Use a link instead of a button worked, but since I am developing for a client I must make everything look the same and use a button. Yes I did copy the code from another Grid that was working and have been scratching my head until I found this site "Thank you GOD".

Solution to fix all...

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack )
{
DataGrid.DataBind();
}
}

What a waste of developer time... ARGH I am dying on my time left on my project...

On to solving streaming an image loaded from Active Directory to a object in memory to presenting it to the end user inside a datalist...

.NET got to love it. 2 more years I should be at the professional level and quote my price for hourly wages... LOL....



Wednesday, July 20, 2005

ADO.NET Accessing Data in a DataSet > DataTable > DataRow

Good Stuff if you return one row from the database.

string strSQL_Table = "Update_Employee";
// Populate Text Boxes with data
txtEmpLanID.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[0].ToString();
txtEmpFirstName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[1].ToString();
txtEmpLastName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[2].ToString();
txtEmpNumber.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[3].ToString();
txtEmpPhone.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[4].ToString();
string param = ds.Tables[strSQL_Table].Rows[0].ItemArray[5].ToString();
Department_dropdown1.Set_dept_value(param);
this.DataBind();

Tuesday, July 12, 2005

SQL Server Query for all values within a month

I have been working on a project at work and I discovered the following works for retrieving dates from SQL Server:

SELECT * FROM view_Employees_Awards WHERE stringDate BETWEEN '2005-06-01' AND
'2005-07-01' ORDER BY Awarded_Date DESC

The following brings back every date from the beginning of 2005-06-01 00:00:00

To

2005-06-01 23:59:59


Monday, July 11, 2005

Moojjoo Blog

Moojjoo Blog

Learning more about C# logic everyday. I needed a dropdown that would display dates in a reverse order so how do you do this.

for (int i = DateTime.Now.Year; i >= 2000; i--)

Simple thanks to the MVP at the forums in MSDN

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"Moojjoo" wrote:

I am building a dropdown select box for year and want to render the dropdown
in reverse order. Using VB I could use step, but I am unsure how to do this
in C#

Any help would be great.

if (!this.IsPostBack)
{
for (int i = 2000; i <= DateTime.Now.Year; i++)
{
int intSubtractTerm = 0;
ListItem newListItem = new ListItem();
intYear = DateTime.Now.Year;
intSubtractTerm = intYear - i;
intYear = intYear - intSubtractTerm;
newListItem.Value = intYear.ToString();
newListItem.Text = intYear.ToString();
DropDownListYear.Items.Add(newListItem);
}
}

Friday, July 08, 2005

Moojjoo Blog - Using User Controls in Datagrid

And the anwser is:

In the code behind:


str_emp_dept = Convert.ToString(((Department_dropdown)e.Item.FindControl("Department_dropdown2")).Selected_dept_value());

WHOOOOOOHOOOOOOO!!!!!!!!!!!!!!


THE QUESTION IS BELOW... WHEN I GET THE ANSWER I WILL POST IT.

I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_value()
{
string dept_value = dept_dropdown.SelectedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department_dropdown id="Department_dropdown1" runat="server"></uc1:department_dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templatecolumn headertext="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropdown2.Selected_dept_value())).SelectedValue;