I have a method which executes on button click event where the textbox is set values from database. but the click event does not show the values on screen, it populates the textboxes, I am getting the values in debugger for text box,the click event is somehow clearing the texctboxes after the method is called, how do I rectify this
This is the method
public void DisplayLead(int EID)
{
DS = new DataSet();
DS = DBM.GetLeadByEnquiryID(EID);
Label2.Text = DBM.Message;
Label1.Text = EID.ToString();
if (DS.Tables[0].Rows.Count > 0)
{
hfCustomerId.Value = DS.Tables[0].Rows[0]["ClientID"].ToString();
txtCName.Text = DS.Tables[0].Rows[0]["ClientName"].ToString();
txtEnq.Text = DS.Tables[0].Rows[0]["Enquiry"].ToString();
txtEnqType.Text = DS.Tables[0].Rows[0]["EnqType"].ToString();
EnqDateTextBox.Text = DS.Tables[0].Rows[0]["Date"].ToString();
if (!DBNull.Value.Equals(DS.Tables[0].Rows[0]["Status"].ToString()))
{
DDLStatus.Items.FindByValue(DS.Tables[0].Rows[0]["Status"].ToString()).Selected = true;
}
txtCP.Text = DS.Tables[0].Rows[0]["Contact"].ToString();
txtEmail.Text = DS.Tables[0].Rows[0]["Email"].ToString();
txtPhone.Text = DS.Tables[0].Rows[0]["Phone"].ToString();
txtComment.Text = DS.Tables[0].Rows[0]["Comment"].ToString();
}
Label2.Text = "test value";
DS = null;
}
This is the button Click event
protected void btnSelect_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
int EID = Convert.ToInt32(row.Cells[0].Text);
DisplayLead(EID);
}
here is the html part
<div class="col-md-6">
<div class="panel panel-body">
<fieldset>
<!-- Enquiry -->
<div class="form-group">
<label class="control-label" for="enq">Enquiry</label>
<div class="">
<asp:TextBox ID="txtEnq" runat="server" CssClass="form-control" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" CssClass="errmsg" ControlToValidate="txtEnq" Display="Dynamic" ErrorMessage="Enquiry is required" validationgroup="LeadsForm"></asp:RequiredFieldValidator>
</div>
</div>
<div class="form-group">
<label class="control-label" for="type">Enquiry Type</label>
<div class="">
<asp:TextBox ID="txtEnqType" runat="server" CssClass="form-control" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="errmsg" ControlToValidate="txtEnqType" Display="Dynamic" ErrorMessage="Type of Enquiry required" validationgroup="LeadsForm" ></asp:RequiredFieldValidator>
</div>
</div>
</fieldSet>
</div>
</div>
</div>
On Page Load
protected void Page_Load(object sender, EventArgs e)
{
Label mpLabel = (Label)Page.Master.FindControl("lblWelcome");
Literal TTLabel = (Literal)Page.Master.FindControl("pagetitle");
if ((mpLabel != null) && (TTLabel != null))
{
mpLabel.Text = "Leads";
TTLabel.Text = "Leads";
}
if (Request.QueryString["Lead"] != null)
{
EID = Convert.ToInt32(Request.QueryString["Lead"].ToString());
if (!IsPostBack)
{
DisplayLead(EID);
}
}
if (!IsPostBack)
{
LoadGrid();
}
//if(!EID.Equals(null) )
// {
// DisplayLead(EID);
// }
}
<div class="panel panel-success">
<div class="panel-heading">Current Leads</div>
<div class="panel-body" style="overflow-x:auto">
<asp:GridView ID="GridView1" CssClass="table table-bordered table-striped table-responsive example2" EnableViewState="true" AutoGenerateSelectButton="false" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound" runat="server">
<Columns>
<asp:BoundField DataField="SNo" HeaderText="S.No" />
<asp:BoundField DataField="ClientName" HeaderText="Client" />
<asp:BoundField DataField="Enquiry" HeaderText="Enquiry" />
<asp:BoundField DataField="EnquiryType" HeaderText="EnquiryType" />
<asp:BoundField DataField="DateofEnq" HeaderText="Date" DataFormatString = "{0:dd-MMM-yyyy}" />
<asp:BoundField DataField="StatusOfEnq" HeaderText="Status" />
<asp:BoundField DataField="ContactPerson" HeaderText="Contact Person" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="ContactPhone" HeaderText="Phone" />
</Columns>
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" CommandName="Select" CommandArgument='<%#Eval("SNo")%>' OnClick="btnSelect_Click" CssClass="btn btn-danger btn-xs margin-bottom" CausesValidation="false" />
<asp:Button type="button" runat="server" Text="Status" ID="btnStatus" CommandName="status" CommandArgument='<%#Eval("SNo")%>' OnCommand="btnStatus_Command" CssClass="btn btn-info btn-xs" CausesValidation="false" data-toggle="modal" data-target="#myModal" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
Related
I have a GridView in which I'm letting users edit previously generated estimates. Everything works fine till I hit recalculate button but after that, all the row values go haywire.
Below is a screenshot of the layout for your reference.
In that, All the details are being fetched from database and few of them are editable and after changing the values, below there is a refresh button which I'm using to recalculate. but my loop is causing them to calculate incorrectly. Please help me rectify my mistake.
below is my aspx code:
<div class="card-body">
<div class="row">
<div class="col-md-12">
<asp:GridView ID="grdPurchaseBill" runat="server" CssClass="table table-bordered table-responsive table-sm" AutoGenerateColumns="False" ShowFooter="false">
<Columns>
<asp:TemplateField HeaderText="Product" ItemStyle-Wrap="false" ControlStyle-Width="100%" ItemStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtProduct" runat="server" CssClass="form-control form-control-sm" Width="100%" Style="width: 100%;" AutoCompleteType="Disabled" autocomplete="off" Text='<%# Eval("product") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight" ItemStyle-Wrap="false" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtWeight" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("weight") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="# of Bags" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtBags" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("bags") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shortage %" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtShortagePercent" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("shortage_percent") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Shortage" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtShortage" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("shortage") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Weight" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtNetWeight" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("net_weight") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtRate" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("rate") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub-Total" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtSubTotal" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("sub_total") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hamali %" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtHamali" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("hamali_percent") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hamali Amt" ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtHamaliAmount" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("hamali") %>' Width="100%" Style="width: 100%;" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Driver Comm. " ItemStyle-Wrap="false" HeaderStyle-Wrap="false" ControlStyle-Width="100%">
<ItemTemplate>
<asp:TextBox ID="txtDriverCommission" runat="server" CssClass="form-control form-control-sm" Text='<%# Eval("driver_commission") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Net Amt" ItemStyle-Wrap="false" ControlStyle-Width="100%" HeaderStyle-Wrap="false">
<ItemTemplate>
<asp:TextBox ID="txtNetAmount" runat="server" CssClass="form-control form-control-sm" Enabled="false" Text='<%# Eval("net_amount") %>' Width="100%" Style="width: 100%;"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Bill Date</label>
<div class="input-group margin input-group-sm">
<asp:TextBox ID="txtBDate" runat="server" CssClass="form-control form-control-sm" TabIndex="1" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
<ajax:CalendarExtender ID="ce1" runat="server" TargetControlID="txtBDate" Format="dd-MM-yyyy" />
<span class="input-group-btn">
<span class="fa fa-times"></span>
</span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Name</label>
<div class="input-group input-group-sm">
<asp:TextBox ID="txtcname" runat="server" CssClass="form-control form-control-sm" TabIndex="2" CausesValidation="True" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
<asp:HiddenField ID="hfCustomerId" runat="server" />
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Phone</label>
<asp:TextBox ID="txtcmobile" runat="server" CssClass="form-control form-control-sm" TabIndex="3" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Address</label>
<asp:TextBox ID="txtcaddress" runat="server" TextMode="MultiLine" TabIndex="6" CssClass="form-control form-control-sm"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Lorry Freight</label>
<asp:TextBox ID="txtLorryFreight" runat="server" TabIndex="6" CssClass="form-control form-control-sm"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Remarks</label>
<asp:TextBox ID="txtRemarks" runat="server" TabIndex="6" CssClass="form-control form-control-sm" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Total Amount</label>
<asp:Label ID="lblTotal" runat="server" CssClass="form-control form-control-sm lblTotal" Text="0" ForeColor="Blue" BackColor="#DEE2E6"></asp:Label>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Payable Amount</label>
<asp:Label ID="lblPayableAmt" runat="server" CssClass="form-control form-control-sm lblPayableAmt" Text="0" ForeColor="Blue" BackColor="#DEE2E6"></asp:Label>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Paid Amount</label>
<asp:TextBox ID="txtPaidAmt" runat="server" CssClass="form-control form-control-sm txtPaidAmt" OnTextChanged="CalculatePaidAmount" AutoPostBack="true" TabIndex="8" ForeColor="Blue" Text="0"></asp:TextBox>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Balance Amount</label>
<div class="input-group input-group-sm">
<label id="lblBalAmt" runat="server" class="form-control form-control-sm lblBalAmt" style="color: red; background-color: #DEE2E6;">0</label>
<span class="input-group-append">
<asp:LinkButton ID="lnkPayable" runat="server" OnClick="ReCalculate" CssClass="btn btn-outline-success btn-flat" Text="" TabIndex="9" CausesValidation="false"><i class="fa fa-sync"></i></asp:LinkButton>
</span>
</div>
</div>
</div>
</div>
</div>
And my aspx.cs code:
protected void GetBillDetails()
{
string query = "select * from estimates where bno='" + Request.QueryString["bno"].ToString() + "';";
grdPurchaseBill.DataSource = dal.GetData(query);
grdPurchaseBill.DataBind();
using (SqlConnection con = new SqlConnection(cm.constring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
txtBDate.Text = dr["bill_date"].ToString();
txtcname.Text = dr["name"].ToString();
txtcmobile.Text = dr["mobileno"].ToString();
txtcaddress.Text = dr["address"].ToString();
txtLorryFreight.Text = dr["lorry_freight"].ToString();
txtRemarks.Text = dr["remarks"].ToString();
lblTotal.Text = dr["grand_total"].ToString();
lblPayableAmt.Text = dr["payable_amount"].ToString();
txtPaidAmt.Text = dr["paid_amount"].ToString();
lblBalAmt.InnerText = dr["balance_amount"].ToString();
bno.InnerText = Request.QueryString["bno"].ToString();
}
}
}
con.Close();
}
}
protected void ReCalculate(object sender, EventArgs e)
{
decimal PayableAmount = 0, PaidAmount = !string.IsNullOrEmpty(txtPaidAmt.Text) ? Convert.ToDecimal(txtPaidAmt.Text) : 0, NetWeight = 0, SubTotal = 0, NetAmount = 0;
foreach (GridViewRow Row in grdPurchaseBill.Rows)
{
TextBox txtProduct = Row.FindControl("txtProduct") as TextBox;
TextBox txtWeight = Row.FindControl("txtWeight") as TextBox;
TextBox txtBags = Row.FindControl("txtBags") as TextBox;
TextBox txtShortagePercent = Row.FindControl("txtShortagePercent") as TextBox;
TextBox txtShortage = Row.FindControl("txtShortage") as TextBox;
TextBox txtNetWeight = Row.FindControl("txtNetWeight") as TextBox;
TextBox txtRate = Row.FindControl("txtRate") as TextBox;
TextBox txtSubTotal = Row.FindControl("txtSubTotal") as TextBox;
TextBox txtHamali = Row.FindControl("txtHamali") as TextBox;
TextBox txtHamaliAmount = Row.FindControl("txtHamaliAmount") as TextBox;
TextBox txtDriverCommission = Row.FindControl("txtDriverCommission") as TextBox;
TextBox txtNetAmount = Row.FindControl("txtNetAmount") as TextBox;
Control txtShortagePercent_ctrl = Row.FindControl("txtShortagePercent") as TextBox;
if (txtShortagePercent_ctrl != null)
{
txtShortage.Text = (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text)) * (Convert.ToDecimal(txtShortage.Text) / 100))).ToString("#0.00");
//txtHamaliAmount.Text = (calculateHamali(Convert.ToDecimal(txtWeight.Text), Convert.ToDecimal(txtHamali.Text))).ToString("#0.00");
decimal TotalHamali = Convert.ToDecimal(txtHamali.Text) > 0 ? ((Convert.ToDecimal(txtWeight.Text) / 100) * Convert.ToDecimal(txtHamali.Text)) : 0;
NetAmount += ((Convert.ToDecimal(txtSubTotal.Text) - TotalHamali));// + Convert.ToDecimal(txtDriverCommission.Text)
txtNetAmount.Text = NetAmount.ToString("#0.00");
txtHamaliAmount.Text = TotalHamali.ToString("#0.00");
NetWeight += (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) * Convert.ToDecimal(txtShortage.Text) / 100));
txtNetWeight.Text = NetWeight.ToString("#0.00");
txtShortage.Text = (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) - (Convert.ToDecimal(txtWeight.Text) * Convert.ToDecimal(txtShortage.Text) / 100))).ToString();
SubTotal += (Convert.ToDecimal(txtNetWeight.Text) * Convert.ToDecimal(txtRate.Text));
txtSubTotal.Text = SubTotal.ToString("#0.00");
TextBox totamt = Row.FindControl("txtNetAmount") as TextBox;
PayableAmount += Convert.ToDecimal(!string.IsNullOrEmpty(totamt.Text) ? totamt.Text : "0");
}
}
lblTotal.Text = (PayableAmount).ToString("#0.00");
lblPayableAmt.Text = (PayableAmount - Convert.ToDecimal(!string.IsNullOrEmpty(txtLorryFreight.Text) ? txtLorryFreight.Text : "0")).ToString("#0.00");
lblBalAmt.InnerText = (PaidAmount > 0 ? Convert.ToDecimal(lblPayableAmt.Text) - PaidAmount : Convert.ToDecimal(lblPayableAmt.Text) - 0).ToString("#0.00");
}
i will try to explain what i have, what i'm trying to do and what is my problem
what i have:
i have a modal with and update panel (i need it because the postback closes my modal) that has two text box, a button and a gridview.
in the textbox i write the name and the surname of a person and with the button i retrieve the data and put it in a gridview.
the gridview has a control to select the row that i want, with that row, i use the data from first three cells to change some hidenField values to use in another function.
in the bottom of the modal i have the add button that only changes a textbox to show that i have the correct data. that button is not enabled by default and the event must enable it
what i want:
i want to select the row that i need, enable the add button and fetch the data in my textbox.
where is my problem:
when i select my row, selectedindexchanging fires but nevers enables the add button so cant fetch my textbox for using it
code:
front code:
<div class="modal fade" id="modalSocio" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabelSocio">
<asp:Label ID="Label4" runat="server" CssClass="text-primary"></asp:Label>
</h5>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<div class="modal-body">
<div class="row g-3">
<div class="row">
<div class="col-3">
<asp:TextBox ID="txtBusquedaNombre" runat="server" CssClass="form-control" placeholder="Nombre"></asp:TextBox>
</div>
<div class="col-3">
<asp:TextBox ID="txtBusquedaApellido" runat="server" CssClass="form-control" placeholder="Apellido"></asp:TextBox>
</div>
<div class="col-3">
<asp:LinkButton ID="btnBuscarSocio" runat="server" CssClass="btn btn-outline-success" Text="Buscar" CausesValidation="false" ToolTip="Buscar" OnClick="btnBuscarSocio_Click" ><span class="fas fa-search"></span></asp:LinkButton>
</div>
</div>
<div class="table-responsive mt-3">
<asp:GridView ID="gvSocios" runat="server" CssClass="table table-bordered" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanging="gvSocios_SelectedIndexChanging" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Legajo" HeaderText="Nro. Socio" ></asp:BoundField>
<asp:BoundField DataField="nombreSocio" HeaderText="Nombre" />
<asp:BoundField DataField="Apellido" HeaderText="Apellido" />
<asp:CommandField ButtonType="Link" HeaderText="Seleccionar" ShowSelectButton="True" SelectText="<i class='fa fa-check-circle'></i>">
<ControlStyle CssClass="btn btn-outline-secondary" />
</asp:CommandField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<EmptyDataTemplate>
<div class="alert alert-primary" role="alert">
No se encontraron registros!
</div>
</EmptyDataTemplate>
</asp:GridView>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="modal-footer">
<asp:Button ID="BtnCancelarSocio" runat="server" Text="Cancelar" CssClass="btn btn-secondary" OnClick="btnCancelar_Click" CausesValidation="False" />
<asp:Button ID="BtnAgregarSocio" ClientIDMode="Static" runat="server" CausesValidation="false" Text="Seleccionar" CssClass="btn btn-success" OnClick="BtnAgregarSocio_Click" />
</div>
</div>
</div>
</div>
codeBehind:
protected void BtnAgregarSocio_Click(object sender, EventArgs e)
{
TxtSocio.Text = hfidNombreSocio.Value;
}
protected void gvSocios_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
var row = gvFormasPago.Rows[e.NewSelectedIndex];
BtnAgregarSocio.Enabled = true;
hfSocio.Value = row.Cells[0].Text;
hfidNombreSocio.Value = row.Cells[0].Text + " - " + row.Cells[1].Text + " " + row.Cells[2].Text;
}
i tried to not use the enabled attribute for test but when the click event fires the hfidNombreSocio value in that moment is empty and the modal never closes.
maybe i'm not using the update panel right.
the text box code:
<div class="row">
<div class="col-md-4">
<asp:Label ID="lblSocio" runat="server" Visible="false" Text="Socio Cuenta Corriente" CssClass="form-label"></asp:Label>
<asp:TextBox ID="TxtSocio" runat="server" text="0" CssClass="form-control" ></asp:TextBox>
<asp:LinkButton ID="btnBuscar" runat="server" Visible="false" CssClass="btn btn-outline-success" Text="Buscar" CausesValidation="false" ToolTip="Buscar" OnClick="btnBuscar_Click" ><span class="fas fa-search"></span></asp:LinkButton> <%-- this button open the modal --%>
</div>
Ok, folks, this is one of those I wish someone corrected me!!
I am MOST HAPPY to have big buckets of egg on my face.
I have for some time preached that when you pop a dialog, you can't have post backs in that dialog. I stand MUCH corrected!!!!
So, lets build a grid, it allows a search, and then we can click on (select the row).
We have this:
<div id="hoteldialog1" style="display:normal">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Enter City Name: <asp:TextBox ID="txtSearchCity" runat="server"></asp:TextBox>
<asp:Button ID="cmdSearchCity" runat="server" Text="Search"
style="margin-left:25px" CssClass="btn" OnClick="cmdSearchCity_Click"/>
<br />
<asp:GridView ID="GridHotels" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" OnSelectedIndexChanged="GridHotels_SelectedIndexChanged"
CssClass="table">
<Columns>
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:Button ID="cmdHSel" runat="server" Text="Select"
CommandName="Select"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
So, when we run, we get/see this:
Now, in above I DID use CommmandName = "select" because I wanted the select row to work. (and I beyond hate all those extra templates). So I used this code to highlight the row.
protected void GridHotels_SelectedIndexChanged(object sender, EventArgs e)
{
// user selected this row - highlight it
int RowIX = GridHotels.SelectedIndex;
GridViewRow gRow = (GridViewRow)GridHotels.Rows[RowIX];
if ((ViewState["MySel"] != null) && ((int)ViewState["MySel"] != RowIX))
{
GridViewRow gLast = GridHotels.Rows[(int)ViewState["MySel"]];
gLast.CssClass = "";
}
gRow.CssClass = "alert-info";
ViewState["MySel"] = RowIX;
}
Ok, so far so simple. And the search button in above is this:
protected void cmdSearchCity_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
using (SqlCommand cmdSQL = new SqlCommand("SELECT * FROM tblHotels ", conn))
{
if (txtSearchCity.Text != "")
{
// filter grid by city
cmdSQL.CommandText += " WHERE City = #City";
cmdSQL.Parameters.Add("#City", SqlDbType.NVarChar).Value = txtSearchCity.Text;
}
conn.Open();
cmdSQL.CommandText += " ORDER BY HotelName";
GridHotels.DataSource = cmdSQL.ExecuteReader();
GridHotels.DataBind();
}
}
}
Again, really simple.
Ok, now the money shot. Now the Rosetta stone. Now the beef, now the magic, now the amazing!!!
The above as noted was placed in a "div", and has a update panel.
So, now lets drop in another grid!!!
We going to display some people, and pop the above hotel selector grid!!
So, we now have this:
<asp:GridView ID="GPeople" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" >
<Columns>
<asp:BoundField DataField="Firstname" HeaderText="Firstname" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdGetHotel" runat="server" Text="Hotels"
OnClick="cmdGetHotel_Click"
OnClientClick="return mypop(this);"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
LoadPeople();
}
void LoadPeople()
{
GPeople.DataSource = MyRst("SELECT * from People Order by FirstName");
GPeople.DataBind();
}
So we now have a grid of people. We now want to on a row click, pop up the hotel list.
So, I suggest jQuery.UI, as is much better (and cleaner then bootstrap dialog).
So we have this row click in above:
<asp:Button ID="cmdGetHotel" runat="server" Text="Hotels"
OnClick="cmdGetHotel_Click"
OnClientClick="return mypop(this);"
/>
So in above, we have both a server side button, and then a client side js function that pops up the dialog (and ONLY returns true if we hit ok.
So, now all we need is the js code to pop up the dialog. That code is this:
<script>
selok = false;
function mypop(btn) {
if (selok)
return true;
var mydiv = $("#hoteldialog1")
mydiv.dialog({
modal: true, appendTo: "form",
title: "Test dialog", closeText: "",
width: "40%",
position: { my: 'left top', at: 'right bottom', of: btn },
buttons: {
Ok: (function () {
selok = true;
btn.click()
}),
Cancel: (function () {
mydiv.dialog("close")
})
}
});
return false;
}
</script>
(set hotel grid display:none - jquery.ui will manage this).
So, now we get this:
So we are free to search, have post-backs, and of course select the row.
If the user hits ok, then the first grid button code runs. I did NOT use the selected index change event for that first grid (I could have), but I used this code:
protected void cmdGetHotel_Click(object sender, EventArgs e)
{
Debug.Print("hotel grid click");
Button btn = (Button)sender;
GridViewRow gRow = (GridViewRow)btn.Parent.Parent;
Debug.Print("Grid row = " + gRow.RowIndex);
Debug.Print("PK = " + GPeople.DataKeys[gRow.RowIndex]["ID"].ToString());
Also note, that while the pop grid is hidden? We can STILL get any data from that row, since the selected index of that grid does persist!!
eg:
GridViewRow gRow = (GridViewRow)GHotels.Rows[GHotels.SelectedIndex];
Debug.Print("Grid row = " + gRow.RowIndex);
Debug.Print("PK = " + GPeople.DataKeys[gRow.RowIndex]["ID"].ToString());
// cells collection, or find control to grab any other value
So, I think you should dump the bootstrap dialog.
Put your 2nd nice grid + searching, post backs - what ever you want into a div with a name, and use jQuery.UI to pop the grid. This will allow searching, post backs and then when the user selects the row and hits ok, then you are now free to close this dialog, and you have "index" of that pop set for you.
I'm using Repeater control to generate tables on my dashboard. In the repeater, is a gridview to display item details. In the first column og the gridview is a dropdownlist to select an item and on selected index of that item, I'm fetching item details and the billing process continues for each table. Now the problem is that I'm only able to get the item details in the first repeater. Nothing happens when I select an item in another table or repeater. kindly help me with this issue.
Here is my ASPX markup:
<div class="row">
<asp:Repeater ID="rptrTables" runat="server" OnItemDataBound="rptrTables_ItemDataBound">
<ItemTemplate>
<div class="col-md-6">
<div class="card card-info">
<div class="card-header with-border">
<h3 class="card-title"><asp:Label ID="lblTableNumber" runat="server" Text='<%# Eval("TableName") %>'></asp:Label></h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<asp:GridView ID="grdOrder" runat="server" AutoGenerateColumns="false" AllowPaging="true" CssClass="table table-bordered table-hover table-responsive" GridLines="None" PageSize="10" OnRowDataBound="gvRowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="true" ControlStyle-CssClass="btn btn-danger fa fa-trash" DeleteText="" HeaderText="Remove" />
<asp:BoundField DataField="RowNumber" HeaderText="Sl. No." />
<asp:TemplateField HeaderText="Item Name">
<ItemTemplate>
<asp:DropDownList ID="drpItemname" runat="server" CssClass="form-control select2" OnSelectedIndexChanged="GetItemDetails" AutoPostBack="true"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Line Total">
<ItemTemplate>
<asp:Label ID="lblLineTotal" runat="server" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Add Item" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" CssClass="btn btn-primary" Text="Add" OnClick="AddItem" CausesValidation="False" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
</div>
<div class="card-footer">
<div class="pull-right">
<asp:Button ID="btnSubmit" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary" Text="Print KOT" />
<asp:Button ID="Button1" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary" Text="Print Final Bill" />
<asp:Button ID="Button2" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary" Text="Complete Order" />
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
And my c# code to fetch item details:
protected void GetItemDetails(object sender, EventArgs e)
{
foreach(RepeaterItem rptrItems in rptrTables.Items)
{
GridView gvItems = (GridView)rptrTables.Items[0].FindControl("grdOrder");
foreach (GridViewRow row in gvItems.Rows)
{
DropDownList ddl = sender as DropDownList;
Control ctrl = row.FindControl("drpItemName") as DropDownList;
if (ctrl != null)
{
DropDownList ddl1 = (DropDownList)ctrl;
if (ddl.ClientID == ddl1.ClientID)
{
Label UnitPrice = row.FindControl("lblUnitPrice") as Label;
Label QTTY = row.FindControl("lblQuantity") as Label;
Label UPrice = row.FindControl("lblUnitPrice") as Label;
Label LINETOTAL = row.FindControl("lblLineTotal") as Label;
SqlConnection conn = new SqlConnection(constring);
conn.Open();
if (ctrl != null)
{
if ((ddl1.ID == ddl.ID) && (ddl1.SelectedIndex == ddl.SelectedIndex))
{
string str = "select * from ItemMaster where ItemName='" + ddl1.SelectedItem.ToString() + "'";
SqlCommand com = new SqlCommand(str, conn);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
UnitPrice.Text = reader["UnitPrice"].ToString();
QTTY.Text = reader["Quantity"].ToString(); ;
decimal totamt = Convert.ToDecimal(QTTY.Text) * Convert.ToDecimal(UnitPrice.Text);
}
reader.Close();
conn.Close();
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "swal", "swal('Item already selected, you can increase the quantity instead!', 'warning');", true);
}
}
}
}
}
}
}
There is a problem in your code. you are always selecting the first item from the repeater control,
GridView gvItems = (GridView)rptrTables.Items[0].FindControl("grdOrder");
Change your code to get the item from foreach loop, so your code will be
GridView gvItems = (GridView)rptrItems.FindControl("grdOrder");
try to use rptrItems instead of the first item of the repeater control each time.
Hope this will help.
I am opening a modal window from the below button (btnOpen). This bhutton is located inside a GridView. It needs to open another Gridview in the modal window but my code is not working:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnOpen" runat="server" Text="Show Gridview" CommandName="cmdDetail" CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
My Modal Window:
<div class="modal" id="idModal">
<div class="container">
<div class="modal-header">
<h1>Transaction Details<a class="close-modal" href="#">×</a></h1>
</div>
<div class="modal-body">
<asp:GridView ID="gvDetail" runat="server" AutoGenerateColumns="false" DataSourceID="SqlgvDetail"
OnRowDataBound="gvDetail_RowDataBound" CssClass="table table-hover table-bordered" EmptyDataText="No data to display." >
<Columns>
<asp:BoundField DataField="metalid" HeaderText="Metal ID"/>
<asp:BoundField DataField="enddate" HeaderText="End Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="startdate" HeaderText="Start Date" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="clientref" HeaderText="Client Ref" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" DataFormatString="{0:N2}" />
</Columns>
</asp:GridView>
</div>
<div class="modal-footer">
<asp:Button ID="btn_close" runat="server" Text="OK" CssClass="close-modal btn-sm btn-primary"/>
</div>
</div>
</div>
<div class="modal-backdrop"></div>
Sql DataSource:
<asp:SqlDataSource ID="SqlgvDetail" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>">
</asp:SqlDataSource>
Code Behind:
protected void gvSummary_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmdDetail")
{
// Retrieve the row index stored in the CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button from the Rows collection.
GridViewRow row = gvSummary.Rows[index];
Button btnOpen = row.FindControl("btnOpen") as Button;
btnOpen.CssClass = "openModal";
string clientRef = row.Cells[0].Text;
SqlgvDetail.SelectCommand = " SELECT td.metalid , td.enddate , td.startdate , td.clientref , td.quantity FROM trxdetail td " +
" WHERE td.clientref = '" + clientRef + "'";
gvDetail.DataBind();
}
}
When I click a button it gets the SQL command correct but doesn't load the modal. If I then click the button again, It brings up the Modal with the SQL command loaded at the first click.
I've been stuck on this for days so any help is appreciated.
I am kind of new to C# and ASP.Net
I want to make a web app where I can add information to a html table to be shown.
Nothing really advanced with MySQL and things like that, just a simple one.
I want to make it possible to add the persons and then later on sort them by their gender (Male, Female), but whatever I try, the list to show them all works, but the 2 other doesn't.
When I add a male, I can see the male, but if I add a female, the male disappears and there comes a female in the other table. And so on..
Here is a gif of what it is doing:
I have tried to make it this way:
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Text;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
int pressAddButton1;
int pressAddButton2;
int pressAddButton3;
Label information1 = new Label();
Label information2 = new Label();
Label information3 = new Label();
static StringBuilder newInfo1 = new StringBuilder();
static StringBuilder newInfo2 = new StringBuilder();
static StringBuilder newInfo3 = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
}
public class Person {
public string Name { get; set; }
public string Gender { get; set; }
public string Mnr { get; set; }
public string Password { get; set; }
public Person(string name, string gender, string mnr, string password)
{
Name = name;
Gender = gender;
Mnr = mnr;
Password = password;
}
}
protected void add_Click(object sender, EventArgs e)
{
Person PersonID = new Person(name.Text, gender.Text, mnr.Text, password.Text);
pressAddButton1++;
if (gender.Text == "Male")
{
pressAddButton2++;
}
if (gender.Text == "Female")
{
pressAddButton3++;
}
information1.ID = "information1" + pressAddButton1;
if (gender.Text == "Male")
{
information2.ID = "information2" + pressAddButton2;
}
if (gender.Text == "Female")
{
information3.ID = "information3" + pressAddButton3;
}
newInfo1.Append(string.Format(#"<tr><td>" + name.Text + "</td><td>" + gender.Text + "</td><td>" + mnr.Text + "</td><td>" + password.Text + "</td></tr>"));
if (gender.Text == "Male")
{
newInfo2.Append(string.Format(#"<tr><td>" + name.Text + "</td><td>" + gender.Text + "</td><td>" + mnr.Text + "</td><td>" + password.Text + "</td></tr>"));
}
if (gender.Text == "Female")
{
newInfo3.Append(string.Format(#"<tr><td>" + name.Text + "</td><td>" + gender.Text + "</td><td>" + mnr.Text + "</td><td>" + password.Text + "</td></tr>"));
}
information1.Text += newInfo1.ToString();
if (gender.Text == "Male")
{
information2.Text += newInfo2.ToString();
}
if (gender.Text == "Female")
{
information3.Text += newInfo3.ToString();
}
Panel1.Controls.Add(information1);
if (gender.Text == "Male")
{
Panel2.Controls.Add(information2);
}
if (gender.Text == "Female")
{
Panel3.Controls.Add(information3);
}
name.Text = "";
mnr.Text = "";
}
}
}
WebForm1.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Person ToString</title>
</head>
<body>
<form id="form1" runat="server">
<div style="border: 1px solid #000; padding: 5px; border-radius: 5px; width: 323px;">
<asp:TextBox ID="name" runat="server" Width="320px" placeholder="Name.."></asp:TextBox>
<br />
<br />
<asp:DropDownList ID="gender" runat="server" Width="324px">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:TextBox ID="mnr" runat="server" Width="320px" placeholder="Member Number.."></asp:TextBox>
<br />
<br />
<asp:TextBox ID="password" runat="server" TextMode="Password" Width="320px" placeholder="Password.."></asp:TextBox>
<br />
<asp:Button ID="add" runat="server" OnClick="add_Click" Text="Add" Width="324px" />
</div>
<br />
All:<br />
<table border="1">
<tr>
<td>Name</td>
<td>Gender</td>
<td>Member Number</td>
<td>Password</td>
</tr>
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
</table>
<br />
Male:
<table border="1">
<tr>
<td>Name</td>
<td>Gender</td>
<td>Member Number</td>
<td>Password</td>
</tr>
<asp:Panel ID="Panel2" runat="server"></asp:Panel>
</table>
<br />
Female:
<table border="1">
<tr>
<td>Name</td>
<td>Gender</td>
<td>Member Number</td>
<td>Password</td>
</tr>
<asp:Panel ID="Panel3" runat="server"></asp:Panel>
</table>
</form>
</body>
</html>
I have heard that maybe it would be easier to use Arraylist and GridView or something, but I don't know how to do it.
Please help.
Here is an example I created. Hope it helps. You can download it here.
It uses a GridView control that is sortable (click on the header text) and a SqlDataSource for data access.
<div class="row" style="margin-top: 50px">
<div class="col-lg-8">
<div class="panel panel-default">
<div class="panel-heading">All Users</div>
<div class="panel-body">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" CssClass="table" GridLines="None" AllowSorting="True">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="MemberNumber" HeaderText="MemberNumber" SortExpression="MemberNumber" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" SelectCommand="SELECT * FROM [User]"></asp:SqlDataSource>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Male Users</div>
<div class="panel-body">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource2" CssClass="table" GridLines="None" AllowSorting="True">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="MemberNumber" HeaderText="MemberNumber" SortExpression="MemberNumber" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" SelectCommand="SELECT * FROM [User] WHERE ([Gender] = #Gender)">
<SelectParameters>
<asp:Parameter DefaultValue="Male" Name="Gender" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Female Users</div>
<div class="panel-body">
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource3" CssClass="table" GridLines="None" AllowSorting="True">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:BoundField DataField="MemberNumber" HeaderText="MemberNumber" SortExpression="MemberNumber" />
<asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" SelectCommand="SELECT * FROM [User] WHERE ([Gender] = #Gender)">
<SelectParameters>
<asp:Parameter DefaultValue="Female" Name="Gender" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">Add User</div>
<div class="panel-body">
<div role="form">
<div class="form-group">
<asp:Label ID="NameLabel" runat="server" Text="Name" AssociatedControlID="NameTextBox"></asp:Label>
<asp:TextBox ID="NameTextBox" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="Label3" runat="server" Text="Gender" AssociatedControlID="GenderDropDownList"></asp:Label>
<asp:DropDownList ID="GenderDropDownList" runat="server" CssClass="form-control">
<asp:ListItem Selected="True" Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="form-group">
<asp:Label ID="Label1" runat="server" Text="Member Number" AssociatedControlID="MemberNumberTextBox"></asp:Label>
<asp:TextBox ID="MemberNumberTextBox" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="form-group">
<asp:Label ID="Label2" runat="server" Text="Password" AssociatedControlID="PasswordTextBox"></asp:Label>
<asp:TextBox ID="PasswordTextBox" runat="server" CssClass="form-control" TextMode="Password"></asp:TextBox>
</div>
<asp:LinkButton ID="AddButton" runat="server" CssClass="btn btn-primary form-control" OnClick="AddButton_Click">Add User</asp:LinkButton>
</div>
</div>
</div>
</div>
</div>
I'm using a nuget package called NPoco to simplify the database insert...
protected void AddButton_Click(object sender, EventArgs e)
{
// Insert new user
using (var db = new Database("DatabaseConnectionString"))
{
db.Insert("User", "Id", true,
new
{
Name = NameTextBox.Text,
Gender = GenderDropDownList.SelectedValue,
MemberNumber = MemberNumberTextBox.Text,
Password = PasswordTextBox.Text
});
}
// Refresh the data in the grid
GridView1.DataBind();
GridView2.DataBind();
GridView3.DataBind();
}