Is there a way to get the value of a label in the item template of a datalist to use in my sql update command in my datalist update command? I don't want to put too much un-needed code in this post so I will try to just put what i thing is needed.
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" CellSpacing="10"
OnCancelCommand="Cancel" OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
CellPadding="10"><ItemTemplate>
<table cellpadding="0" cellspacing="0" class="style8"><tr>
<td bgcolor="#CCCCCC" align="right">
<asp:LinkButton ID="Edit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="Delete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
</td></tr>
<tr>
<td align="center" bgcolor="#CCCCCC">
Install Date:
<%# DataBinder.Eval(Container.DataItem, "installDate", "{0:MM/dd/yyyy}") %>
</td>
</tr>
<tr><td bgcolor="#99CCFF" align="center"><asp:Label ID="InstallName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "installName")%>' AccessKey="1"></asp:Label></td></tr><tr>
And the C#..
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CurrentWeek();
}
}
public void CurrentWeek()
{
SqlCommand cmd = new SqlCommand("SELECT install_Add.*, Checklist.progressCount FROM install_Add INNER JOIN Checklist ON install_Add.installName = Checklist.installName where install_Add.installDate between '" + beginDate + "' and '" + endDate + "' and checklist.active= '1'", cs);
cmd.CommandType = CommandType.Text;
cmd.Connection = cs;
cs.Open();
DataList1.DataSourceID = "";
DataList1.DataSource = cmd.ExecuteReader();
DataList1.DataBind();
cs.Close();
}
break;
}
}
protected void Update(object source, DataListCommandEventArgs e)
{
TextBox installDateTextBox = (TextBox)e.Item.FindControl("editInstallDate");
string newInstallDate = installDateTextBox.Text.Replace("'", "''");
TextBox installNameTextBox = (TextBox)e.Item.FindControl("editInstallName");
string newInstallName = installNameTextBox.Text.Replace("'", "''");
Response.Write(installNameTextBox.Text);
Response.Write(newInstallName);
TextBox equipTextBox = (TextBox)e.Item.FindControl("editequipment");
string newequip = equipTextBox.Text.Replace("'", "''");
TextBox Contact1NameTextBox = (TextBox)e.Item.FindControl("editContact1Name");
string newContact1Name = Contact1NameTextBox.Text.Replace("'", "''");
TextBox Contact2NameTextBox = (TextBox)e.Item.FindControl("editContact2Name");
string newContact2Name = Contact2NameTextBox.Text.Replace("'", "''");
TextBox Contact3NameTextBox = (TextBox)e.Item.FindControl("editContact3Name");
string newContact3Name = Contact3NameTextBox.Text.Replace("'", "''");
TextBox Contact4NameTextBox = (TextBox)e.Item.FindControl("editContact4Name");
string newContact4Name = Contact4NameTextBox.Text.Replace("'", "''");
TextBox Contact5NameTextBox = (TextBox)e.Item.FindControl("editContact5Name");
string newContact5Name = Contact5NameTextBox.Text.Replace("'", "''");
TextBox Contact1EmailTextBox = (TextBox)e.Item.FindControl("editContact1Email");
string newContact1Email = Contact1EmailTextBox.Text.Replace("'", "''");
TextBox Contact2EmailTextBox = (TextBox)e.Item.FindControl("editContact2Email");
string newContact2Email = Contact2EmailTextBox.Text.Replace("'", "''");
TextBox Contact3EmailTextBox = (TextBox)e.Item.FindControl("editContact3Email");
string newContact3Email = Contact3EmailTextBox.Text.Replace("'", "''");
TextBox Contact4EmailTextBox = (TextBox)e.Item.FindControl("editContact4Email");
string newContact4Email = Contact4EmailTextBox.Text.Replace("'", "''");
TextBox Contact5EmailTextBox = (TextBox)e.Item.FindControl("editContact5Email");
string newContact5Email = Contact5EmailTextBox.Text.Replace("'", "''");
DropDownList Contact1Role = (DropDownList)e.Item.FindControl("editContact1Role");
string newContact1Role = Contact1Role.SelectedValue;
DropDownList Contact2Role = (DropDownList)e.Item.FindControl("editContact2Role");
string newContact2Role = Contact2Role.SelectedValue;
DropDownList Contact3Role = (DropDownList)e.Item.FindControl("editContact3Role");
string newContact3Role = Contact3Role.SelectedValue;
DropDownList Contact4Role = (DropDownList)e.Item.FindControl("editContact4Role");
string newContact4Role = Contact4Role.SelectedValue;
DropDownList Contact5Role = (DropDownList)e.Item.FindControl("editContact5Role");
string newContact5Role = Contact5Role.SelectedValue;
TextBox Contact1PhoneTextBox = (TextBox)e.Item.FindControl("editContact1Phone");
string newContact1Phone = Contact1PhoneTextBox.Text.Replace("'", "''");
TextBox Contact2PhoneTextBox = (TextBox)e.Item.FindControl("editContact2Phone");
string newContact2Phone = Contact2PhoneTextBox.Text.Replace("'", "''");
TextBox Contact3PhoneTextBox = (TextBox)e.Item.FindControl("editContact3Phone");
string newContact3Phone = Contact3PhoneTextBox.Text.Replace("'", "''");
TextBox Contact4PhoneTextBox = (TextBox)e.Item.FindControl("editContact4Phone");
string newContact4Phone = Contact4PhoneTextBox.Text.Replace("'", "''");
TextBox Contact5PhoneTextBox = (TextBox)e.Item.FindControl("editContact5Phone");
string newContact5Phone = Contact5PhoneTextBox.Text.Replace("'", "''");
DropDownList InstallTech = (DropDownList)e.Item.FindControl("editInstallTech");
string newInstallTech = InstallTech.SelectedValue;
DropDownList SecondInstallTech = (DropDownList)e.Item.FindControl("editSecondInstallTech");
string newSecondInstallTech = SecondInstallTech.SelectedValue;
DropDownList HelpDeskTech = (DropDownList)e.Item.FindControl("editHelpDeskTech");
string newHelpDeskTech = HelpDeskTech.SelectedValue;
SqlCommand cmd1 = new SqlCommand("Update install_Add_Test set installName = '" + newInstallName + "', equipInstalled = '" + newequip + "', contact1Name = '" + newContact1Name + "', contact1email = '" + newContact1Email + "', contact1role = '" + newContact1Role + "', contact1phone = '" + newContact1Phone + "', contact2name = '" + newContact2Name + "', contact2email = '" + newContact2Email + "', contact2role = '" + newContact2Role + "', contact2phone = '" + newContact2Phone + "', contact3name = '" + newContact3Name + "', contact3email = '" + newContact3Email + "', contact3Role = '" + newContact3Role + "', contact3phone = '" + newContact3Phone + "', contact4name = '" + newContact4Name + "', contact4email = '" + newContact4Email + "', contact4role = '" + newContact4Role + "', contact4phone = '" + newContact4Phone + "', contact5name = '" + newContact5Name + "', contact5email = '" + newContact5Email + "', contact5role = '" + newContact5Role + "', contact5phone = '" + newContact5Phone + "', installTech = '" + newInstallTech + "', secondInstallTech = '" + newSecondInstallTech + "', helpdeskTech = '" + newHelpDeskTech + "', installTechEmail = '" + TechEmail + "', helpdeskEmail = '" + helpdeskEmail + "', secondTechEmail = '" + SecondTechEmail + "' where installName = '" + (TextBox)e.Item.FindControl("editInstallName") + "'", cs);
cs.Open();
cmd1.ExecuteNonQuery();
cs.Close();
DataList1.EditItemIndex = -1;
CurrentWeek();
The textbox "installName" will not update when the update command is executed but all other fields will. HELP!