ASP.NET C# If else is ignored? - c#

I've been scratching my head for over two hours. I just can't seem to figure it out.
Basically what I did was have "Winner" show up under status when I click on select bidder button. The problem is when I pick the bottom select bidder button then activate buttons above it. The if else decision that displays the error message "Cannot select winner. Error cause: You have already selected a winner." is ignored and proceeds to write "Winner" on the status field.
The error message will show if I try to do it the other way though. Pick the button in the first row to set the status to winner then picking the second row button will tell me I can't pick a winner because I already have picked somebody else.
My C# code:
protected void rptrBindBidders_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Winner" && e.CommandArgument.ToString() != "")
{
Int64 onsaleID = Convert.ToInt64(Request.QueryString["saleID"]);
String CS = ConfigurationManager.ConnectionStrings["DatabaseSQLConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
using (SqlCommand cmd1 = new SqlCommand("select * from Bidders where saleID=" + onsaleID + " ", con))
{
SqlDataAdapter sda = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
sda.Fill(dt);
string BidderStatus = dt.Rows[0]["BidderStatus"].ToString().Trim();
if (BidderStatus == "Winner")
{
lblmessage.ForeColor = Color.Red;
lblmessage.Text = "Cannot select winner. Error cause: You have already selected a winner.";
}
else
{
using (SqlCommand cmd = new SqlCommand("update Bidders set [BidderStatus]='Winner' where [bidID]='" + e.CommandArgument.ToString() + "'", con))
{
con.Open();
cmd.ExecuteNonQuery();
lblmessage.ForeColor = Color.Green;
lblmessage.Text = "Success! A bidder has been selected!";
con.Close();
}
}
this.BindBidders();
}
}
}
}
}
My HTML Code:
<asp:Repeater ID="rptrBindBidders" onItemCommand="rptrBindBidders_ItemCommand" runat="server">
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th>Bidders</th>
<th>Date bidded</th>
<th>Price Offer</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("BidderName") %></td>
<td><%#Eval("DateBidded") %></td>
<td>₱<%# Eval("bidPrice") %></td>
<td><%# Eval("BidderStatus") %></td>
<td><asp:Button ID="btnSelectBuyer" runat="server" Text="Select Bidder" CommandName="Winner" CommandArgument='<%#Eval("bidID") %>'/></td>
<!--<asp:HiddenField ID="hfbidID" Value='' runat="server" />-->
<!--<asp:HiddenField ID="hfBidderName" Value='' runat="server" />-->
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>

Can you use SqlDataReader to check whether you have a winner directly, without having to fill a DataTable?
using(var connection = new SqlConnection(cs)
{
// SELECT 1 because we don't care about the returned data
using(var cmd = new SqlCommand($"SELECT 1 FROM [Bidders] WHERE saleID={onsaleID} AND BidderStatus='Winner'", connection))
{
cmd.CommandType = CommandType.Text;
using(var reader = cmd.ExecuteReader())
{
if(reader.Read())
{
// The command returned rows (there is an existing winner for the given `onsaleID`)
}
else
{
// The command returned no rows. There is no winner.
}
}
}
}

You probably confused bidId and saleId. I guess that can exist many Bidders with same saleId and different BidId.
Basically you are just searching for all bidders and than check status for first one. So your code will evaluate this " if (BidderStatus == "Winner")" to true only if first item is selected. Change Your select to "select count(1)", add where clause to select only winners and then check if it returns more than 0. It should work.

Related

Selected check box in the list view item template is not storing

I'm trying to store the selected rows using asp:checkbox to the CourseParticipants table but it doesn't store the selected records to the database. There is no error shown but it refresh to the same page and shows the checked records. I'm trying to select users.
Thank you in advance!
Here is the markup:
<table class="table table-hover">
<thead style="background-color: #92d36e">
<tr>
<td><b>Employee Name</b></td>
<td><b>Position</b></td>
<td><b>Actions</b></td>
</tr>
</thead>
<tbody>
<asp:ListView ID="lvEmployees" runat="server" OnPagePropertiesChanging="lvEmployees_PagePropertiesChanging" OnDataBound="lvEmployees_DataBound">
<ItemTemplate>
<tr>
<td><%# Eval("FirstName")%>,<%# Eval("LastName")%></td>
<td><%# Eval("Position")%></td>
<td><asp:CheckBox ID="cbEmployee" runat="server" />
</a></td>
</tr>
</ItemTemplate>
</asp:ListView>
</tbody>
</table>
<asp:Button ID="btnAddParticipants" runat="server"
class="btn btn-success" OnClick="btnAddParticipants_Click"
Text="Add Participants" />
Here is the C#
void GetEmployees()
{
using (SqlConnection con = new SqlConnection(Helper.GetCon()))
{
con.Open();
string query = #"SELECT EmployeeID, FirstName, LastName, Position FROM Employees";
using (SqlCommand cmd = new SqlCommand(query, con))
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "EmployeeID");
lvEmployees.DataSource = ds;
lvEmployees.DataBind();
con.Close();
}
}
}
protected void btnAddParticipants_Click(object sender, EventArgs e)
{
foreach (ListViewDataItem item in this.lvEmployees.Items)
{
string idValue = lvEmployees.DataKeys[item.DataItemIndex].Value.ToString();
if (item.ItemType == ListViewItemType.DataItem)
{
CheckBox cb = (CheckBox)item.FindControl("cbEmployee");
if (cb.Checked)
{
using (SqlConnection con = new SqlConnection(Helper.GetCon()))
{
con.Open();
string query = #"INSERT INTO CourseParticipants VALUES (#TrainingModuleID, #EmployeeID, #Active, #DateAdded)";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("#TrainingModuleID", txtCourseID.Text);
cmd.Parameters.AddWithValue("#EmployeeID", idValue);
cmd.Parameters.AddWithValue("#Active", 1);
cmd.Parameters.AddWithValue("#DateAdded", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
}
If it's always DateTime.Now what you want to insert, you could use the getdate() function:
string query = #"INSERT INTO CourseParticipants VALUES (#TrainingModuleID, #EmployeeID, #Active, getdate())";
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("#TrainingModuleID", txtCourseID.Text);
cmd.Parameters.AddWithValue("#EmployeeID", idValue);
cmd.Parameters.AddWithValue("#Active", 1);
cmd.ExecuteNonQuery();
}
But it's a bit DB specific, so what DB are you using?
https://learn.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql?view=sql-server-2017
I would also cast/convert txtCourseID.Text to an int (32 or 64) depending on your db scheme. Just to make sure that it's an OK value... and not string (nvarchar).
I also removed the closing of the connection, since it's in a using block.

How to hold the values static on the page

I want to make the values of a text box and labels static on the page when user goes from attendance page to another page I have set the enableviewstate="true" but still its not holding the data when I go to another page it vanishes.
Here is my html code:
<tr>
<td class="auto-style3">Login Time:</td>
<td class="auto-style4">
<asp:Label ID="lblLogin" enableviewstate="true" runat="server"></asp:Label>
</td>
<td class="auto-style5">Logout Time:</td>
<td>
<asp:Label ID="lblLogout" enableviewstate="true" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style3">Remarks:</td>
<td class="auto-style4">
<asp:TextBox ID="TextBoxRemarks" runat="server" enableviewstate="true" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
Here is my c-sharp code:
TimeSpan logintime = System.DateTime.Now.TimeOfDay;
TimeSpan time = TimeSpan.Parse("09:20:00.000");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblAttendance.Text = Session["user"].ToString().Split('^')[1];
lblDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
if (btnLogin.Text == "Login(Daily Attendance)")
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Track_UserLog", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#EmployeeId", Session["user"].ToString().Split('^')[0]);
cmd.ExecuteNonQuery();
con.Close();
lblLogin.Text = System.DateTime.Now.ToString("hh:mm");
btnLogin.Text = "Logout(Daily Attendance)";
if (logintime > time)//&& TextBoxRemarks.Text.ToString() == String.Empty)
{
DateTime today = DateTime.Today;
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
cn.Open();
SqlCommand cd = new SqlCommand("update tblAttendanceDetails set Remarks=#rem where LoginDate=convert(date,GETDATE()) AND EmployeeId=' " + Session["User"].ToString().Split('^')[0] + " '", cn);
cd.Parameters.AddWithValue("#rem", TextBoxRemarks.Text);
cd.ExecuteNonQuery();
cn.Close();
}
}
else if (btnLogin.Text == "Logout(Daily Attendance)")
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["REGDataConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Track_logout", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#EmployeeId", Session["user"].ToString().Split('^')[0]);
cmd.ExecuteNonQuery();
lblLogout.Text = System.DateTime.Now.ToString("hh:mm");
btnLogin.Text = "Login(Daily Attendance)";
}
}
Viewstate works for only same page postbacks.
From MSDN:
View state provides state information for a specific ASP.NET page. If you need to use information on more than one page, or if you need the information to persist across visits to the Web site, you must use another method for maintaining state. You can use application state, session state, or profile properties.
If you want to see same data when you get request that page you should store data in application state, session state, or profile properties.
Then you should manually bind this data to pages elements.

Setting different values to td for asp:Repeater

I've recently started working with <asp:Repeater/>. I have a table in the database with the following columns
ID
Message
Flag
I'm not allowed to alter the table in any way. The messages that are stored are from managers and employees. Only way to find out which message belongs to who is by the Flag column which has manager or employee flag. Now I need to read from this table and display it on a webform developed in asp.net. I can read the values no problem but the issue is that I need to display it as a convo one after another so i've used a <asp:Repeater/> but I can't seem to put the messages in different td for example
First row should have manager messages
Second row should have employee messages
The code below is my effort so far.
Markup
<ItemTemplate>
<tr>
<td class="manager">
<%:GetMessage("manager") %>
</td>
</tr>
<tr>
<td class="employee">
<%:GetMessage("employee") %>
</td>
</tr>
And the C# code
protected string GetMessage(string flagIndicator)
{
using (SqlConnection connection = new SqlConnection(Common.ConnectionString))
{
string myQuery = #"SELECT MESSAGES FROM MYTABLE WHERE FLAG = #flag";
using (SqlCommand cmd = new SqlCommand(myQuery, connection))
{
cmd.Parameters.AddWithValue("#flag", flagIndicator);
connection.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Message = reader["MESSAGES"].ToString();
MyRepeater.DataSource = reader;
MyRepeater.DataBind();
}
}
}
}
//How to return the messages so they are spilt up by the flag
}
private string Message { get; set; }
Thanks in advance for your help
View:
<asp:Repeater ID="pageList" runat="server">
<ItemTemplate>
<tr>
<td class='<%# ((System.Data.DataRowView)Container.DataItem)["Flag"]%>'>
<%# ((System.Data.DataRowView)Container.DataItem)["Message"]%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
Code Behind:
private void Page_PreRender(object sender, EventArgs e)
{
pageList.DataSource = GetAllMessages();
pageList.DataBind();
}
Business:
protected DataTable GetAllMessages()
{
using (SqlConnection connection = new SqlConnection(Common.ConnectionString))
{
string myQuery = #"SELECT MESSAGES FROM MYTABLE";
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
DataSet messagesDS = new DataSet();
adapter.Fill(messagesDS, "MYTABLE");
return messagesDS.Tables[0];
}
}

Dropdown value disappears after submit

I have a textbox whose values goes into the dropdown on button click. The problem is that when I fill all the data and submit the form. And when I come second time to see that value it disappears from the dropdown. What should I do to make the value gets in the dropdown fix. Please see the code for your reference:
<tr>
<td class="td">Location/City</td>
<td>
<asp:DropDownList CssClass="txtfld-popup" ID="ddlLocation" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator CssClass="error_msg" ID="reqLocation" ControlToValidate="ddlLocation" runat="server" ErrorMessage="Please enter location" InitialValue="--Select--" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtOtherCity" runat="server" Visible="false" CssClass="txtfld-popup"></asp:TextBox>
<asp:Button ID="btnAddDropDown" runat="server" Width="63" Text="Add" CausesValidation="false" OnClick="btnAddDropDown_Click1" />
</td>
</tr>
Also, see the code behind for your reference:-
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlLocation.SelectedItem.Text == "Other")
{
txtOtherCity.Visible = true;
}
else
{
txtOtherCity.Visible = false;
}
}
protected void btnAddDropDown_Click1(object sender, EventArgs e)
{
string city = txtOtherCity.Text.Trim();
if (!string.IsNullOrEmpty(city))
{
ddlLocation.Items.Add(new ListItem(city, city));
}
}
You have to store the values from the textbox into the table dbo.Cities in database. Next time when you will come back to the same page then dropdown will fetch data from db.
Then on btnAddDropDown_Click1() you should insert the value of the city from the 'txtOtherCity' TextBox to the respective table, and then bind the DropDown of the city again. Something Like
protected void btnAddDropDown_Click1(object sender, EventArgs e)
{
string strconnection = System.Configuration.ConfigurationManager.AppSettings["YourConnectionString"].ToString();
string city = txtOtherCity.Text.Trim();
DataSet ds=new DataSet();
if (!string.IsNullOrEmpty(city))
{
// Your code to insert the value of the city from the 'txtOtherCity' `TextBox` to the respective table
//Edit: this is a very rudimentary code
string query = "INSERT INTO Career.Location (State) " +
"VALUES (#city) ";
// create connection and command
using(SqlConnection cn = new SqlConnection(strconnection))
using(SqlCommand cmd = new SqlCommand(query, cn))
{
// define parameters and their values
cmd.Parameters.Add("#city", SqlDbType.VarChar, 50).Value = city;
// open connection, execute INSERT, close connection
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
query = "select State from Career.Location";
using(SqlConnection cnn = new SqlConnection(strconnection))
using(SqlCommand cmdd = new SqlCommand(query, cnn))
{
SqlDataAdapter adp = new SqlDataAdapter(cmdd);
cnn.Open();
adp .Fill(ds);
cnn.Close();
}
ddlLocation.DataSource=ds;
ddlLocation.DataTextField = "State";
ddlLocation.DataValueField = "State";
ddlLocation.DataBind();
}
}
Do you have functionality of inserting the data in the DB (not only adding the new item in the drop down list). You have to insert the city in the appropriate table to be able to see it later on.
The implementation depends on your architecture, the implementation of the DAL etc.
For example - if you are using ADO.NET, you can insert the values in the table with a stored procedure:
CREATE PROCEDURE Add_City
#CityName varchar(50),
#StateID int
AS
BEGIN
INSERT INTO dbo.Cities (CityName, StateID) values (#CityName, #StateID)
END
GO
And then call it from the app. Something like that:
using (SqlConnection con = new SqlConnection("the connection string"))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Add_City";
cmd.Parameters.Add("#CityName", SqlDbType.VarChar).Value = txtCity.Text.Trim();
cmd.Parameters.Add("#StateID", SqlDbType.Int).Value = CountryId;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
// lblMessage.Text = "City inserted successfully!";
}
catch (Exception ex)
{
throw ex; // Or log or handle somehow the exception
}
}
I got the answer for this solution, Please see the code for your reference:-
protected void BindContrydropdown()
{
//conenction path for database
//string connection = WebConfigurationManager.ConnectionStrings["myconn"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select Id,CityName From Career.Location", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddllocation1.DataSource = ds;
ddllocation1.DataTextField = "CityName";
ddllocation1.DataValueField = "Id";
ddllocation1.DataBind();
ddllocation1.Items.Insert(0, new ListItem("--Select--", "0"));
ddllocation1.Items.Insert(1, new ListItem("--OTHER--", "0"));
con.Close();
}
}
protected void ddllocation1_SelectedIndexChanged(object sender, EventArgs e)
{
string country = "India";
var cities = _helper.GetLocations(country, ddllocation1.SelectedValue);
cities.Insert(0, "--Select--");
cities.Insert(1, "Other");
ddlLocation.DataSource = cities;
ddlLocation.DataBind();
}
protected void btnAddDropDown_Click1(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
//BindContrydropdown();
//if (txtOtherCity.Text != "")
//{
// txtOtherCity.Text = "";
//}
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Add_CityforLocation";
cmd.Parameters.Add("#ID", SqlDbType.VarChar).Value = 0;
cmd.Parameters.Add("#CountryName", SqlDbType.VarChar).Value = "India";
cmd.Parameters.Add("#CityName", SqlDbType.VarChar).Value = txtOtherCity.Text.Trim();
cmd.Parameters.Add("#StateName", SqlDbType.VarChar).Value = ddlLocation.SelectedItem.ToString();
cmd.Connection = con;
try
{
// con.Open();
cmd.ExecuteNonQuery();
BindContrydropdown();
// lblMessage.Text = "City inserted successfully!";
}
catch (Exception ex)
{
Response.Write(ex.Message);//You Can Haave Messagebox here
}
finally
{
con.Close();
}
}
}
Also see the html of the dropdowns:-
<tr>
<td class="td">Location/State</td>
<td>
<asp:DropDownList CssClass="txtfld-popup" ID="ddllocation1" OnSelectedIndexChanged="ddllocation1_SelectedIndexChanged" runat="server" AutoPostBack="true"></asp:DropDownList>
<asp:RequiredFieldValidator CssClass="error_msg" ID="RequiredFieldValidator1" ControlToValidate="ddllocation1" runat="server" ErrorMessage="Please enter location" InitialValue="--Select--" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="td">Location/City</td>
<td>
<asp:DropDownList CssClass="txtfld-popup" ID="ddlLocation" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator CssClass="error_msg" ID="reqLocation" ControlToValidate="ddlLocation" runat="server" ErrorMessage="Please enter location" InitialValue="--Select--" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtOtherCity" runat="server" Visible="false" CssClass="txtfld-popup"></asp:TextBox>
<asp:Button ID="btnAddDropDown" runat="server" Width="63" Text="Add" CausesValidation="false" OnClick="btnAddDropDown_Click1" />
</td>
</tr>
And this solved my,
Also see the Stored procedure for the same:-
Alter PROCEDURE [dbo].[Add_CityforLocation]
-- Add the parameters for the stored procedure here
#ID int,
#CountryName nvarchar(100),
#StateName nvarchar(100),
#CityName varchar(100)
AS
BEGIN
INSERT INTO Career.Location(CountryName, StateName, CityName) values (#CountryName,#StateName,#CityName)
END
GO

How to make each button respond to that row only

I have a Repeater which creates a table for multiple row with the same field name:
<asp:Repeater runat="server" ID="rptContent">
<HeaderTemplate>
<table border="0" style="width: 95%;">
<tr>
<td style="width: 25%;">Name</td>
<td style="width: 25%;">Last Four SSN #</td>
<td style="width: 25%;">PDF Generator</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("name").ToString() %></td>
<td><%# Eval("ssn3").ToString() %></td>
<td><asp:Button ID="btnGeneratePDF" runat="server" Text="Generate PDF For" onclick="btnGeneratePDF_Click" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
My code behind looks like this:
public void writeData()
{
Conn = new SqlConnection(cString);
Conn.Open();
nameE = txtName.Text;
var pdfPath = Path.Combine(Server.MapPath("~/PDFTemplates/9.pdf"));
// Get the form fields for this PDF and fill them in!
var formFieldMap = PDFHelper.GetFormFieldNames(pdfPath);
formFieldMap["topmostSubform[0].Page1[0].f1_01_0_[0]"] = txtName.Text;
sqlCode = "SELECT * FROM [db].[dbo].[TablePDFTest] WHERE [name] = '" + nameE + "'";
using (SqlCommand command = new SqlCommand(sqlCode, Conn))
{
command.CommandType = CommandType.Text;
using (reader = command.ExecuteReader())
{
if (reader.HasRows)
{
if (reader.Read())
{
formFieldMap["topmostSubform[0].Page1[0].f1_02_0_[0]"] = reader.GetValue(1).ToString();
formFieldMap["topmostSubform[0].Page1[0].f1_04_0_[0]"] = reader.GetValue(2).ToString();
formFieldMap["topmostSubform[0].Page1[0].f1_05_0_[0]"] = reader.GetValue(3).ToString();
formFieldMap["topmostSubform[0].Page1[0].f1_07_0_[0]"] = reader.GetValue(4).ToString();
formFieldMap["topmostSubform[0].Page1[0].social[0].TextField1[0]"] = reader.GetValue(5).ToString();
formFieldMap["topmostSubform[0].Page1[0].social[0].TextField2[0]"] = reader.GetValue(6).ToString();
formFieldMap["topmostSubform[0].Page1[0].social[0].TextField2[1]"] = reader.GetValue(7).ToString();
formFieldMap["topmostSubform[0].Page1[0].social[0].TextField2[2]"] = reader.GetValue(8).ToString();
formFieldMap["topmostSubform[0].Page1[0].social[0].TextField2[3]"] = reader.GetValue(9).ToString();
}
}
}
}
// Requester's name and address (hard-coded)
formFieldMap["topmostSubform[0].Page1[0].f1_06_0_[0]"] = "Medical Group\n2700 Wr Ave\nPurchase, NY 10232";
var pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap);
PDFHelper.ReturnPDF(pdfContents, "Compl.pdf");
}
How can I make it so if there are more than one entries each button will query by [name] where the last four ssn is different?
First, just a nod to using parameters...
Anyway, a lot of ways to do this, but one could be to add a commandargument value to your button (and then evaluate it in your code behind).
<asp:Button
ID="btnGeneratePDF"
runat="server"
Text="Generate PDF For"
CommandArgument = '<%# Eval("L4_SSN") %>'
onclick="btnGeneratePDF_Click" />
Then you'd need to make sure you had a field in your SELECT statement such as RIGHT(SSN,4) as L4_SSN
And finally, you'd modify your btnGeneratePDF_Click sub to evaluate e.CommandArgument...

Categories