I have a function that checks the database to see if the current user is a primary user (this value is called "Type" in the database and is a bit value of 1 or 0--a primary user has a Type of 1) and if the address in the address listing is a billing address (which is represented by the "IsBilling" value in the database which is also a bit value of 0 or 1. If the address is a billing address, then the IsBilling value is 1. If the address is a shipping address, then the value is 0).
What I am trying to do is to show the edit address button ONLY to those users who are primary users--otherwise, it should be hidden. I don't want to hide the edit button for the shipping addresses, though.
Right now, I can't seem to target the billing address--Whenever I set the bool variable ShowButton to true or false, this ends up applying to all the edit buttons.
I checked the SELECT query in the database and it does bring back all the correct values based on the current user id. But I am not sure why I can't choose when to show/hide the button for the Billing Address.
This is the function:
protected bool ShowButton(int UserId)
{
bool ShowButton = false;
try
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
cn.Open();
SqlCommand cmd = new SqlCommand("SELECT Type, IsBilling FROM CustomerUsers INNER JOIN Addresses ON uidUser = Addresses.UserId WHERE uidUser = #UserId", cn);
cmd.Parameters.Add(new SqlParameter("#UserId", UserId));
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (Convert.ToInt16(reader["Type"]) == 0 && Convert.ToInt16(reader["IsBilling"]) == 1)
{
ShowButton = false;
}
}
}
cn.Close();
}
}
catch (Exception ex)
{
Response.Write("ERROR: " + ex.Message.ToString() + "<br />");
}
return ShowButton;
}
This is the repeater with the EditAddressButton:
<asp:Repeater ID="ShipToAddressList" runat="server" OnItemCommand="ShipToAddressList_ItemCommand" >
<ItemTemplate>
<div class="entry aEntry" >
<div class="caption">
<h2><asp:Literal ID="AddressCaption" runat="server" Text='<%#((bool)Eval("IsBilling"))?"Billing Address":"Shipping Address" %>'></asp:Literal></h2>
<span class="links">
<asp:LinkButton ID="EditAddressButton" runat="server" CommandArgument='<%#Eval("AddressId")%>' Visible = '<%# ShowButton(Convert.ToInt32(Eval("UserId"))) %>' CommandName="Edit" CssClass="link"><asp:Image ID="Image1" ImageUrl="/app_themes/cartbuttons/btn_Edit.jpg" runat="server" /></asp:LinkButton><%-- --%>
<br />
<asp:LinkButton ID="DeleteAddressButton" runat="server" CommandArgument='<%#Eval("AddressId")%>' CommandName="Del" Visible='<%#!((bool)Eval("IsBilling")) %>' OnClientClick="return confirm('Are you sure to delete this address?');" CssClass="link" ><asp:Image ID="Image2" ImageUrl="/app_themes/cartbuttons/btn_Delete.jpg" runat="server" /></asp:LinkButton>
</span>
</div>
<div class="address">
<asp:Literal ID="Address" runat="server" Text='<%#Container.DataItem.ToString()%>'></asp:Literal>
<br /><asp:Literal ID="phoneAndEmail" runat="server" Text='<%# getPhoneAndEmail(AlwaysConvert.ToInt(Eval("AddressId"))) %>'></asp:Literal>
</div>
<div class="buttons">
<br /><br />
<asp:LinkButton ID="PickAddressButton" runat="server" SkinID="Button" CommandName="Pick" CommandArgument='<%#Eval("AddressId")%>' CssClass="button"><asp:Image ID="ImagePick" runat="server" ImageUrl="/app_themes/cartbuttons/btn_Ship.jpg" /></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Related
I have a repeater, one column of which contains a textbox on which is attached a JQuery datepicker along with an update button. So a user uses the datepicker to change the date, clicks update and it writes to the database.The original date and the record id are stored in hidden fields.
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:HiddenField ID="hidThisID" Value='<%# Eval("orderID") %>' runat="server" />
<asp:HiddenField ID="hidPrevDueDate" Value='<%# Eval("Duebeforedate", "{0:dd/MM/yyyy}") %>' runat="server" />
<input type="text" class="form-control fc-datepicker duedateinput" style="width: 150px" value='<%# Eval("Duebeforedate", "{0:dd/MM/yyyy}") %>' runat="server" id="fccd" readonly />
<asp:LinkButton ID="btnDateUpdate" OnClick="btnDateUpdate_Click" CssClass="btn btn-primary btn-sm" runat="server" ToolTip="Approved"> Update </asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
which calls this function
protected void btnDateUpdate_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
HtmlInputText htmlDueDate = (HtmlInputText)item.FindControl("fccd");
HiddenField hidID = (HiddenField)item.FindControl("hidThisID");
HiddenField hidOldDate = (HiddenField)item.FindControl("hidPrevDueDate");
DateTime prevDueDate = Convert.ToDateTime(hidOldDate.Value.ToString());
DateTime newDueDate = Convert.ToDateTime(htmlDueDate.Value.ToString());
string ID = hidID.Value;
if (prevDueDate != newDueDate)
{
string query = "update [tblOrders] set Duebeforedate=CONVERT(datetime,'" + newDueDate.ToString() + "', 103) where [orderID] = '" + ID + "'";
//database stuff here
}
}
}
However, the newDueDate variable still holds the original due date. Consequently the old and new dates match and so the database doesn't get updated. How do I get it to store the new value?
For two-way data binding you need to use the Bind keyword instead of Eval
Fixed it, it wasn't the btnUpdate function at all, I'd forgotten this check -
if (!IsPostBack)
{
//bind the repeater
}
I'm having trouble exiting edit mode after performing an insert. Inserting isn't done through radgrid but passively through the code behind. I tried everything but I can't exit after completing the insert.
protected void btnInsertUpdate_Click(object sender, EventArgs e)
{
RadButton btnInsert = (RadButton)sender;
RadTextBox txtVisited = (RadTextBox)btnInsert.Parent.FindControl("txtVisited");
RadTextBox txtDays = (RadTextBox)btnInsert.Parent.FindControl("txtDays");
if (txtVisited.Text != "" & txtDays.Text != "" & !IsAsync)
{
string RECORD_UID = ds_01.InsertParameters["RECORD_UID"].DefaultValue;
string VISITED = txtVisited.Text;
string DAYS_ON_SITE = txtDays.Text;
DB db = new DB();
SqlCommand cmd = new SqlCommand();
db.ActiveDBConn = "dbConnection";
cmd.CommandText = "ACP_CANADA_INSERT_NEW_RECORD_DETAILS";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("UID", RECORD_UID);
cmd.Parameters.AddWithValue("VISITED", VISITED);
cmd.Parameters.AddWithValue("DAYS_ON_SITE", DAYS_ON_SITE);
db.SQLStatement = cmd;
db.NonQuery();
radgrid_1.MasterTableView.ClearEditItems();
}
}
<EditFormSettings EditFormType="Template" FormStyle-BackColor="#e1eaff" FormStyle-BorderColor="#006699" FormStyle-BorderWidth="10">
<FormTemplate>
<div style="padding: 10px;">
<div>
<telerik:RadLabel ID="lblVisited" runat="server" Text="Visited:"></telerik:RadLabel>
<telerik:RadTextBox ID="txtVisited" runat="server"></telerik:RadTextBox>
<br />
<br />
<telerik:RadLabel ID="lblDays" runat="server" Text="Days on Site:"></telerik:RadLabel>
<telerik:RadTextBox ID="txtDays" runat="server"></telerik:RadTextBox>
</div>
<br />
<br />
<telerik:RadButton id="btnInsertUpdate" runat="server" Text="Insert" OnClick="btnInsertUpdate_Click"></telerik:RadButton>
<telerik:RadButton id="btnCancel" text="Cancel" runat="server" causesvalidation="False" CommandName="Cancel"></telerik:RadButton>
</div>
</FormTemplate>
</EditFormSettings>
Adding the CommandName equal to "Cancel" gives me the behavior I'm looking for...Insert is performed to the database and I get to exit out of edit mode.
<telerik:RadButton id="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" CommandName="Cancel"></telerik:RadButton>
My Requirement is. I will be uploading 3-4 images at a time through FileUpload. Each Image will have its own Title, Descriptions etc.
Now my issue is that, whenever uploading I have given a title column for the images. But when I upload 3-4 Images the title and description is going same for all the images.
Here Is my HTML for the Image Uploading via FileUpload.
<tr>
<td style="vertical-align: top;">
<asp:label cssclass="control-label" id="Label1" runat="server">Image Title</asp:label>
</td>
<td>
<div class="control-group">
<div class="controls">
<asp:textbox id="txtImagetitle" cssclass="form-control" runat="server" validationgroup="AddNew"></asp:textbox>
<asp:requiredfieldvalidator cssclass="error-class" id="RequiredFieldValidator1" runat="server"
controltovalidate="txtImagetitle" errormessage="Please add the image title" validationgroup="AddNew"></asp:requiredfieldvalidator>
</div>
</div>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<asp:label cssclass="control-label" id="Label2" runat="server">Image description</asp:label>
</td>
<td>
<div class="control-group">
<div class="controls">
<asp:textbox id="txtImagedesc" cssclass="form-control" runat="server" validationgroup="AddNew"></asp:textbox>
<asp:requiredfieldvalidator cssclass="error-class" id="RequiredFieldValidator2" runat="server"
controltovalidate="txtImagedesc" errormessage="Please add the image description"
validationgroup="AddNew"></asp:requiredfieldvalidator>
</div>
</div>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<asp:label cssclass="control-label" id="Label3" runat="server">Image upload</asp:label>
</td>
<td>
<div class="control-group">
<div class="controls">
<asp:fileupload id="FileUpload1" runat="server" allowmultiple="true" />
<asp:requiredfieldvalidator cssclass="error-class" id="RequiredFieldValidator3" runat="server"
controltovalidate="FileUpload1" errormessage="Please add the gallery date" validationgroup="AddNew"></asp:requiredfieldvalidator>
</div>
</div>
</td>
</tr>
Please suggest what to do in this case when uploading multiple images how to set different titles for different Images.
UPDATED CODE BEHIND
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request.QueryString.Count > 0)
{
foreach (var file in FileUpload1.PostedFiles)
{
string filename = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("/GalleryImages/" + filename));
using (SqlConnection conn = new SqlConnection(conString))
if (Request.QueryString["Id"] != null)
{
string Id = Request.QueryString["Id"];
SqlCommand cmd = new SqlCommand();
cmd.CommandText = " Update tbl_galleries_stack SET gallery_id=#gallery_id,img_title=#img_title,img_desc=#img_desc,img_path=#img_path, IsDefault=#IsDefault Where Id=#Id";
cmd.Parameters.AddWithValue("#Id", Id);
cmd.Parameters.AddWithValue("#gallery_id", ddlgallery.SelectedValue);
cmd.Parameters.AddWithValue("#img_title", txtImagetitle.Text);
cmd.Parameters.AddWithValue("#img_desc", txtImagedesc.Text);
cmd.Parameters.AddWithValue("#img_path", filename);
cmd.Parameters.AddWithValue("#IsDefault", chkDefault.Checked);
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Gallery updated sucessfully');window.location ='csrgalleriesstack.aspx';", true);
}
}
}
else
{
foreach (var file in FileUpload1.PostedFiles)
{
string filename = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("/GalleryImages/" + filename));
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString);
using (SqlCommand cmd = conn.CreateCommand())
{
conn.Open();
SqlCommand cmd1 = new SqlCommand("Insert into tbl_galleries_stack (gallery_id,img_title,img_desc,img_path,IsDefault) values(#gallery_id,#img_title, #img_desc, #img_path,#IsDefault)", conn);
cmd1.Parameters.Add("#gallery_id", SqlDbType.Int).Value = ddlgallery.SelectedValue;
cmd1.Parameters.Add("#img_title", SqlDbType.NVarChar).Value = txtImagetitle.Text;
cmd1.Parameters.Add("#img_desc", SqlDbType.NVarChar).Value = txtImagedesc.Text;
cmd1.Parameters.Add("#img_path", SqlDbType.NVarChar).Value = filename;
cmd1.Parameters.Add("#IsDefault", SqlDbType.Bit).Value = chkDefault.Checked;
cmd1.ExecuteNonQuery();
conn.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Gallery added sucessfully');window.location ='csrgalleriesstack.aspx';", true);
}
}
}
}
There is no way you can give different title / description as you have given no option to provide it. Period.
You are forced to use multiple fileupload controls. This is also tricky because asp:FileUpload controls wont maintain their state after postback.
So, the solution I can see is a two-part one. Create two panels and hide the second panel at page load
Part 1
Place a label and textbox and button like this in the first panel in your page.
When the user enters a value, say 10, and fires EnterButton_click close Panel1 and open Panel2.
Part 2
On Panel 2, place a GridView like this
<asp:GridView ID="ImagesGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Sl No">
<ItemTemplate><%# Container.DisplayIndex + 1 %></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:TextBox ID="txtTitle" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<asp:FileUpload ID="flUpload" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="SaveButton" Text="Save" runat="server" OnClick="SaveButton_Click"/>
Now on the Enter buttons click event on Panel 1, write this.
// the idea is to create an empty gridview with number of rows client selected
protected void EnterButton_Click(object sender, EventArgs e)
{
//in this, 10 has been entered
var imageCount = Convert.ToInt32(txtImageCount.Text);
//var list = new List<string>();
//for (int i = 0; i < imageCount; i++)
//{
// list.Add(string.Empty);
//}
var list = new List<string>(10);
list.AddRange(Enumerable.Repeat(String.Empty, imageCount));
ImagesGrid.DataSource = list;
ImagesGrid.DataBind();
//TO DO: hide panel1 and make panel2 visible
}
So on clicking enter, you will get an empty gridview with ten rows.
Now fill the rows in the GridView, do validation and hit Save. On Save Button click event, you can access the WebControls like this.
protected void SaveButton_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in ImagesGrid.Rows)
{
var title = row.FindControl("txtTitle") as TextBox;
var description = row.FindControl("txtDescription") as TextBox;
var imageFile = row.FindControl("flUpload") as FileUpload;
string filename = Path.GetFileName(imageFile.FileName);
imageFile.SaveAs(Server.MapPath("/GalleryImages/" + filename));
//TO DO: write save routine
}
}
It looks like you only have one set of inputs tied to a single file upload with multiple turned on.
You will either want to turn off multiple and allow the user to add reported sets of those images, or have the editing of title, etc happen in a gridview with the upload.
You could also support a"holding cell " where they upload and then must enter that information before you actually save it to your data store.
I have a Listview which I have used to display messages.Along with each message there is a link to "Reply" message.Since different user can send message to one user.The user have different message from different user.Now i need to track each user who are sending message.I was wondering if there is a way to know which message is selected so that the sender's id can be traced.
Here is my List view.
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /><i style=" color:Gray; " > from
<asp:Label ID="tme" runat="server" Text='<%#Eval("name")%>' />
<i> on </i>
<asp:Label ID="tmelbl" runat="server" Text='<%#Eval("tme")%>'/>
<a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
<hr style=" margin-top:1px; margin-bottom:1px; " />
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
</ItemTemplate>
</asp:ListView>
With this list view i display the messages.In the above code you can see this line <a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
So,when I click the icon a lightbox appears(modal of bootstrap) where i can write my message.
This lightbox has a button to send message(insert to database) which is as follows.
public void reply_msg(object sender, EventArgs e)
{
string tym = DateTime.Now.ToString();
string sid = Session["userid"].ToString();
//string rid = ((Label)msg_list.FindControl("easy")).Text;
//Label mr = (Label)msg_list.FindControl("reg_id_reply");
// string rid = mr.Text;
string rid = Session["msgreply"].ToString();
//msg_list.Items.FindControl("easy");
sc.connection();
SqlCommand cmd = new SqlCommand("insert into message(msg,senderId,receiverId,tme) values( #msg,#sid,#rid,#tme) ", sc.con);
cmd.Parameters.AddWithValue("#msg", ReplyMsgTb.Text);
cmd.Parameters.AddWithValue("#sid", sid);
cmd.Parameters.AddWithValue("#rid", rid);
cmd.Parameters.AddWithValue("#tme", tym);
cmd.ExecuteNonQuery();
sc.con.Dispose();
sc.con.Close();
}
What i need is to know which item of ListView is selected when i click the icon that brings out the lightbox to send message.
OR is there any other way to know which item of Listview is selected.
You can use check box with every row. So when the user checks the check box for the particular row you can easily reply to the selected user.
your code will be something like this:-
<asp:ListView ID="msg_list" runat="server">
<ItemTemplate>
<table>
<tr class="myitem">
<td>
<asp:TemplateField HeaderText="Id" ItemStyle-HorizontalAlign="Left">
<ItemTemplate >
<asp:CheckBox ID="chkRow" onclick ="CheckSingleCheckbox(this)" AutoPostBack="true" runat="server" OnCheckedChanged="chkRow_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:Label role="menuitem" ID="msg_lbl" runat="server" text='<%#Eval("msg")%>' /><i style=" color:Gray; " > from
<asp:Label ID="tme" runat="server" Text='<%#Eval("name")%>' />
<i> on </i>
<asp:Label ID="tmelbl" runat="server" Text='<%#Eval("tme")%>'/>
<a id="msg-reply" class="btn button" data-toggle="modal" data-target="#msg-rply" style="cursor:pointer;" ><i class="glyphicon glyphicon-share-alt white"> </i></a> </td>
<hr style=" margin-top:1px; margin-bottom:1px; " />
</tr>
</table>
<%--<hr style=" margin-top:1px; margin-bottom:1px; " />--%>
you can use the script given below for finding which check box has been checked:-
<script type="text/javascript">
function CheckSingleCheckbox(ob) {
var grid = ob.parentNode.parentNode.parentNode;
var inputs = grid.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
if (ob.checked && inputs[i] != ob && inputs[i].checked) {
inputs[i].checked = false;
}
}
}
}
</script>
I am working on a small search form that has two text fields: One that allows users to search for a job list (which is basically a wish list--don't know why they want to call it a "job list" but whatever) by entering in part of or a full email address or someone's first and/or last name (This textbox is called SearchName). This field is required and if it is blank when the user hits "Search," an error message appears telling them so. The second textbox is optional, and it allows users to enter in a city or a state to help narrow their search down even more (this textbox is called SearchLocation).
I have a function (called getJobLists()) that is used by the search button to get results.
As it is right now, the part of the function that returns results based on what is entered into the SearchName field works perfectly. However, I cannot get any results for SearchLocation. When I enter a valid email or name into SearchName, then enter a valid city or state into SearchLocation, I get no results. However, if I enter in anything invalid (i.e. a city that is not associated with the entered email or name) the "no results found" message does appear.
I have tested both SQL queries in my search function in SQL Server Management Studio and they do work perfectly.
I have a try-catch inside the search function, but no error is being shown, not even in the console.
This is the code behind:
protected void Page_Load(object sender, System.EventArgs e)
{
// CHECK IF THE WISHLIST SEARCH ENABLED
StoreSettingsManager settings = AbleContext.Current.Store.Settings;
if (!settings.WishlistSearchEnabled)
{
Response.Redirect(AbleCommerce.Code.NavigationHelper.GetHomeUrl());
return;
}
}
protected void getJobLists()
{
try
{
if (SearchName.Text != "")
{//if SearchName.Text is not blank
if (SearchLocation.Text != "")
{//check to see if SearchLocation.Text is not blank either
string sqlSelect = "SELECT (FirstName +' '+ LastName) AS 'FullName', UserName, (Address1 + ', ' +City + ', ' + Province) AS 'Address' FROM ac_Users INNER JOIN ac_Wishlists ON ac_Wishlists.UserId = ac_Users.UserId INNER JOIN ac_Addresses ON ac_Addresses.UserId = ac_Wishlists.UserId WHERE IsBilling ='true' AND (UserName LIKE '%'+#UserName+'%' OR (FirstName + LastName) LIKE '%'+#UserName+'%') AND ((City + Province) LIKE '%'+#Location+'%')";
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
SqlCommand cmd = new SqlCommand(sqlSelect, cn);
cmd.Parameters.AddWithValue("#UserName", String.Format("%{0}%", SearchName.Text));
cmd.Parameters.AddWithValue("#Location", String.Format("%{0}%", SearchLocation.Text));
cmd.CommandType = CommandType.Text;
cn.Open();
DataSet ds = new DataSet();
DataTable jobsListsTbl = ds.Tables.Add("jobsListsTbl");
jobsListsTbl.Columns.Add("User", Type.GetType("System.String"));
jobsListsTbl.Columns.Add("PrimaryAddress", Type.GetType("System.String"));
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
DataRow dr = jobsListsTbl.NewRow();
dr["User"] = reader["Name"];
dr["PrimaryAddress"] = reader["Address"];
jobsListsTbl.Rows.Add(dr);
}
}
WishlistGrid.DataSource = ds;
WishlistGrid.DataMember = "jobsListsTbl";
WishlistGrid.DataBind();
}
}//end of if(SearchLocation.Text !='')
else
{//if SearchLocation.Text is blank, then go with this code instead
string sqlSelect2 = "SELECT (FirstName +' '+ LastName) AS 'FullName', UserName, (Address1 + ', ' +City + ', ' + Province) AS 'Address' FROM ac_Users INNER JOIN ac_Wishlists ON ac_Wishlists.UserId = ac_Users.UserId INNER JOIN ac_Addresses ON ac_Addresses.UserId = ac_Wishlists.UserId WHERE IsBilling ='true' AND (UserName LIKE '%'+#UserName+'%' OR (FirstName + LastName) LIKE '%'+#UserName+'%')";
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
SqlCommand cmd = new SqlCommand(sqlSelect2, cn);
cmd.Parameters.AddWithValue("#UserName", String.Format("%{0}%", SearchName.Text));
cmd.CommandType = CommandType.Text;
cn.Open();
DataSet ds = new DataSet();
DataTable jobsListsTbl2 = ds.Tables.Add("jobsListsTbl2");
jobsListsTbl2.Columns.Add("User", Type.GetType("System.String"));
jobsListsTbl2.Columns.Add("PrimaryAddress", Type.GetType("System.String"));
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
DataRow dr = jobsListsTbl2.NewRow();
dr["User"] = reader["UserName"];
dr["PrimaryAddress"] = reader["Address"];
jobsListsTbl2.Rows.Add(dr);
}
}
WishlistGrid.DataSource = ds;
WishlistGrid.DataMember = "jobsListsTbl2";
WishlistGrid.DataBind();
}
}//end if SearchLocation.Text is empty
}//end of if SearchName.Text !==''
}
catch (Exception x)
{
errors5.Text += "ERROR: " + x.Message.ToString() + "<br />";
}
}
protected void SearchButton_Click(object sender, EventArgs e)
{
WishlistGrid.Visible = true;
getJobLists();
}
And this is the designer code for the search form (Note: the NavigateUrl is not set for the hyperlink yet. I will set it once everything is displaying properly for the search results):
<div id="findWishlistPage" class="mainContentWrapper">
<div class="section">
<div class="introDiv">
<div class="pageHeader">
<h1>Find a Job List</h1>
</div>
<div class="content">
<asp:label id="errors" runat="server" text=""></asp:label>
<asp:label id="errors2" runat="server" text=""></asp:label>
<asp:label id="errors3" runat="server" text=""></asp:label>
<asp:label id="errors4" runat="server" text=""></asp:label>
<asp:label id="errors5" runat="server" text=""></asp:label>
<asp:UpdatePanel ID="Searchajax" runat="server">
<ContentTemplate>
<asp:Panel ID="SearchPanel" runat="server" EnableViewState="false" DefaultButton="SearchButton">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableViewState="false" />
<table class="inputForm">
<tr>
<th class="rowHeader">
<asp:Label ID="SearchNameLabel" runat="server" Text="Name or E-mail:" AssociatedControlID="SearchName" EnableViewState="false"></asp:Label>
</th>
<td>
<asp:Textbox id="SearchName" runat="server" onfocus="this.select()" Width="200px" EnableViewState="false"></asp:Textbox>
<asp:RequiredFieldValidator ID="SearchNameValdiator" runat="server" ControlToValidate="SearchName"
Text="*" ErrorMessage="Name or email address is required." EnableViewState="false"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<th class="rowHeader">
<asp:Label ID="SearchLocationLabel" runat="server" Text="City or State (optional):" EnableViewState="false"></asp:Label>
</th>
<td>
<asp:TextBox id="SearchLocation" runat="server" onfocus="this.select()" Width="140px" EnableViewState="false"></asp:TextBox>
<asp:LinkButton ID="SearchButton" runat="server" CssClass="button linkButton" Text="Search" OnClick="SearchButton_Click" EnableViewState="false" />
</td>
</tr>
</table><br />
<asp:GridView ID="WishlistGrid" runat="server" AllowPaging="True"
AutoGenerateColumns="False" ShowHeader="true"
SkinID="PagedList" Visible="false" EnableViewState="false">
<Columns>
<asp:TemplateField HeaderText="Name">
<HeaderStyle CssClass="wishlistName" />
<ItemStyle CssClass="wishlistName" />
<ItemTemplate>
<asp:HyperLink ID="WishlistLink" runat="server" >
<%#Eval("User")%>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<HeaderStyle CssClass="wishlistLocation" />
<ItemStyle CssClass="wishlistLocation" />
<ItemTemplate>
<asp:Label ID="Location" runat="server" Text='<%#Eval("PrimaryAddress")%>'></asp:Label>
<%--'<%#GetLocation(Eval("User.PrimaryAddress"))%>'--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Localize ID="EmptySearchResult" runat="server" Text="There were no job lists matching your search criteria."></asp:Localize>
</EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
Can anyone please tell me what I'm missing or doing wrong?
Okay, I finally solved the issue. Apparently, it was a variable naming issue I kept overlooking. But now it all works okay! :)