Instantly share code, notes, and snippets.

@rbipin /button.aspx Secret
Last active Dec 10, 2017

Embed
What would you like to do?
AspGridView_WithCustomeColumn_For_TextBox
<div>
<asp:Button ID="btnApproveOrder" ClientIDMode="Predictable" Text="Approve Order" runat="server" CssClass="button" CommandName="ApproveOrder" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" />
<asp:Button ID="btnClear" ClientIDMode="Predictable" Text="Clear" runat="server" CssClass="button" />
</div>
protected void aspGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = 0;
string ordernum = string.Empty;
string approverid = string.Empty;
UpdateData updateDataInDb = null;
try
{
switch (e.CommandName)
{
case "ApproveOrder":
rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = aspGridView.Rows[rowIndex];
approverid = ((TextBox)row.FindControl("txtApproveId")).Text.ToString().Trim();
ordernum = row.Cells[0].Text.ToString().Trim();
updateDataInDb = new UpdateData();
updateDataInDb.UpdateApproverId(ordernum, approverid);
break;
}
}
catch (Exception ex)
{
throw ex;
}
}
protected void aspGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button approveOrderBtn = null;
Button clearnBtn = null;
DataRowView datarow = null;
Label approvedBy = null;
Label alertText = null;
TextBox approvalid = null;
HtmlGenericControl approvalSection = null;
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
datarow = (DataRowView)e.Row.DataItem;
if (!string.IsNullOrEmpty(datarow[5].ToString()))
{
approvalSection = (HtmlGenericControl)e.Row.FindControl("ApprovalSection");
approvalSection.Visible = false;
approvedBy = (Label)e.Row.FindControl("txtapprovedBy");
approvedBy.Visible = true;
}
else
{
approveOrderBtn = (Button)e.Row.FindControl("btnApproveOrder");
clearnBtn = (Button)e.Row.FindControl("btnClear");
alertText = (Label)e.Row.FindControl("alertMsg");
approvalid = (TextBox)e.Row.FindControl("txtApproveId");
if (approveOrderBtn != null)
approveOrderBtn.OnClientClick = "return ValidateInput('" + approvalid.ClientID + "','" + alertText.ClientID + "')";
if (clearnBtn!=null)
clearnBtn.OnClientClick= "return ClearInputField('"+approvalid.ClientID+"')";
}
}
}
catch (Exception ex)
{
throw ex;
}
}
<asp:GridView ID="aspGridView" runat="server" AutoGenerateColumns="false" Width="100%" style="margin-top:20px;" OnRowCommand="aspGridView_RowCommand" OnRowDataBound="aspGridView_RowDataBound">
<Columns>
<asp:BoundField HeaderText="Order Number" DataField="ORD_NUM" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Order Amount" DataField="ORD_AMOUNT" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Order Date" DataField="ORD_DATE" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Customer Date" DataField="CUST_NAME" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Order Description" DataField="ORD_DESCRIPTION" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Approve Order">
<ItemTemplate>
<section id="ApprovalSection" runat="server" style="margin-top: 5px;">
<div class="approveUserIdSection">
<asp:TextBox ID="txtApproveId" ClientIDMode="Predictable"
placeholder="Approver ID"
runat="server"
MaxLength="11"></asp:TextBox>
<asp:Label ID="alertMsg"
ClientIDMode="Predictable"
runat="server"
CssClass="validatorMsgGrid"></asp:Label>
</div>
<div>
<asp:Button ID="btnApproveOrder" ClientIDMode="Predictable" Text="Approve Order" runat="server" CssClass="button" CommandName="ApproveOrder" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" />
<asp:Button ID="btnClear" ClientIDMode="Predictable" Text="Clear" runat="server" CssClass="button" />
</div>
</section>
<asp:Label ID="txtapprovedBy" runat="server" Visible="false" Text='<%# "Approved By " + Eval("APPROVAL_ID") %>' CssClass="approvedByMsg"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment