Is there a way that I can use an excel spreadsheet that would then feed into my html / c# program. I have as many as 10 dropdownlists(DDL) that all have different values(example: {Ram [8, 16, 32, 64]} and another being {City[HSV, DAL, SLC, DNV]}, hard-coded into them in the html layer. Those DDL's names and values represent data that is in an excel spreadsheet. I need to write code that pulls certain data from the spreadsheet if and only if that particular value was selected within the DDL. ALL of the things I have tried looking through try to get me to import the spreadsheet and use it like a spreadsheet inside a panel or something. I need to have a way that lets me tinker with it more like a database. I need to be able to write functions/statements that operate like SQL Queries. Thank you for taking the time to read this and your attempt at helping me out.
HTML
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Find.aspx.cs" Inherits="VirginiaCollege.Find" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BorderColor="White" BorderStyle="None">
<br />
<br />
<asp:Label ID="Label11" runat="server" Text="Select what type of user you are..."></asp:Label>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>IT Admin</asp:ListItem>
<asp:ListItem>Executive Management</asp:ListItem>
<asp:ListItem>Academic Director</asp:ListItem>
<asp:ListItem>Teachers</asp:ListItem>
<asp:ListItem>Students</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btSubmitUserType" runat="server" BorderStyle="Ridge" Text="Submit Selection" BackColor="#CCCCCC" OnClick="btSubmitUserType_Click" />
<br />
<br />
</asp:Panel>
<asp:Panel ID="Panel6" runat="server" Visible="false" >
<asp:Label ID="lblEnterPsWrd" runat="server" Text="Please enter the password"></asp:Label>
<br />
<br />
<asp:TextBox ID="tbPassword" runat="server" placeholder="Password" > </asp:TextBox>
<asp:Label ID="Label12" runat="server" Text="Password = Admin"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmitUserTypePsWrd" runat="server" BorderStyle="Ridge" Text="Submit Password" BackColor="#CCCCCC" OnClick="btSubmitUserTypePsWrd_Click" />
</asp:Panel>
<asp:Panel ID="Panel7" runat="server" Visible="false" >
<asp:Label ID="lblEnterPsWrd2" runat="server" Text="Please enter the password"></asp:Label>
<br />
<br />
<asp:TextBox ID="tbPassword2" runat="server" placeholder="Password" ></asp:TextBox>
<asp:Label ID="Label13" runat="server" Text="Password = Director"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmitUserTypePsWrd2" runat="server" BorderStyle="Ridge" Text="Submit Password" BackColor="#CCCCCC" OnClick="btSubmitUserTypePsWrd2_Click" />
</asp:Panel>
<asp:Panel ID="Panel8" runat="server" Visible="false" >
<asp:Label ID="lblEnterPsWrd3" runat="server" Text="Please enter the password"></asp:Label>
<br />
<br />
<asp:TextBox ID="tbPassword3" runat="server" placeholder="Password" ></asp:TextBox>
<asp:Label ID="Label14" runat="server" Text="Password = Student"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmitUserTypePsWrd3" runat="server" BorderStyle="Ridge" Text="Submit Password" BackColor="#CCCCCC" OnClick="btSubmitUserTypePsWrd3_Click" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" Visible="false">
<asp:CheckBox ID="cbCity" runat="server" Text="City" />
<br />
<asp:CheckBox ID="cbComputerType" runat="server" Text="Computer Type" />
<br />
<asp:CheckBox ID="cbDepartment" runat="server" Text="Department" />
<br />
<asp:CheckBox ID="cbRoomNumber" runat="server" Text="Room Number" />
<br />
<asp:CheckBox ID="cbComputerPosition" runat="server" Text="Computer Postition" />
<br />
<asp:CheckBox ID="cbGraphicsCard" runat="server" Text="Graphics Card" />
<br />
<asp:CheckBox ID="cbRAM" runat="server" Text="RAM" />
<br />
<asp:CheckBox ID="cbProgram" runat="server" Text="Program" />
<br />
<asp:CheckBox ID="cbInstallDate" runat="server" Text="Install Date" />
<br />
<asp:CheckBox ID="cbExperationDate" runat="server" Text="Experation Date" />
<br />
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit Search Criteria" />
</asp:Panel>
<asp:Panel ID="Panel3" runat="server" Visible="false">
<asp:CheckBox ID="cbComputerType2" runat="server" Text="Computer Type" />
<br />
<asp:CheckBox ID="cbDepartment2" runat="server" Text="Department" />
<br />
<asp:CheckBox ID="cbRoomNumber2" runat="server" Text="Room Number" />
<br />
<asp:CheckBox ID="cbGraphicsCard2" runat="server" Text="Graphics Card" />
<br />
<asp:CheckBox ID="cbRAM2" runat="server" Text="RAM" />
<br />
<asp:CheckBox ID="cbProgram2" runat="server" Text="Program" />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Submit Search Criteria" />
</asp:Panel>
<asp:Panel ID="Panel4" runat="server" Visible="false">
<asp:CheckBox ID="cbComputerType3" runat="server" Text="Computer Type" />
<br />
<asp:CheckBox ID="cbGraphicsCard3" runat="server" Text="Department" />
<br />
<asp:CheckBox ID="cbRAM3" runat="server" Text="Room Number" />
<br />
<asp:CheckBox ID="cbProgram3" runat="server" Text="Graphics Card" />
<br />
<br />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Submit Search Criteria" />
</asp:Panel>
<br />
<br />
<br />
<asp:Panel ID="Panel5" runat="server" Visible="false" HorizontalAlign="Left">
<asp:Label ID="Label1" runat="server" Text="Select City..." Visible="False"></asp:Label>
<asp:DropDownList ID="ddlCity" runat="server" Visible="False">
<asp:ListItem>HSV</asp:ListItem>
<asp:ListItem>DAL</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label2" runat="server" Text="Select Computer Type" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlComputerType" runat="server" Visible="False">
<asp:ListItem>CSTU</asp:ListItem>
<asp:ListItem>CAD</asp:ListItem>
<asp:ListItem>Staff</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label3" runat="server" Text="Select Department" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlDepartment" runat="server" Visible="False">
<asp:ListItem>3D Imaging</asp:ListItem>
<asp:ListItem>Accounting</asp:ListItem>
<asp:ListItem>Business</asp:ListItem>
<asp:ListItem>Recruiting</asp:ListItem>
<asp:ListItem>Management</asp:ListItem>
<asp:ListItem>Teaching</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label4" runat="server" Text="Select Room Number" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlRoomNumber" runat="server" Visible="False">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>31</asp:ListItem>
<asp:ListItem>32</asp:ListItem>
<asp:ListItem>33</asp:ListItem>
<asp:ListItem>34</asp:ListItem>
<asp:ListItem>35</asp:ListItem>
<asp:ListItem>36</asp:ListItem>
<asp:ListItem>37</asp:ListItem>
<asp:ListItem>38</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label5" runat="server" Text="Select Computer Position" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlComputerPosition" runat="server" Visible="False">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>31</asp:ListItem>
<asp:ListItem>32</asp:ListItem>
<asp:ListItem>33</asp:ListItem>
<asp:ListItem>34</asp:ListItem>
<asp:ListItem>35</asp:ListItem>
<asp:ListItem>36</asp:ListItem>
<asp:ListItem>37</asp:ListItem>
<asp:ListItem>38</asp:ListItem>
<asp:ListItem>39</asp:ListItem>
<asp:ListItem>40</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label6" runat="server" Text="Select Graphics Card" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlGraphicsCard" runat="server" Visible="False">
<asp:ListItem>Dell Nvidia Tesla K40 GPU Computing Processor</asp:ListItem>
<asp:ListItem>Dell 6 GB Nvidia Tesla K20X GPU Computing Processor</asp:ListItem>
<asp:ListItem>Dell 2 GB Nvidia Quadro K620 Graphics Card</asp:ListItem>
<asp:ListItem>Nvidia Quadro K6000 SDI I/O</asp:ListItem>
<asp:ListItem>VisionTek CryoVenom R9 290</asp:ListItem>
<asp:ListItem>Nvidia GeForce GTX 780</asp:ListItem>
<asp:ListItem>AMD Radeon R9 295X2</asp:ListItem>
<asp:ListItem>AMD Radeon R9 290</asp:ListItem>
<asp:ListItem>MSI R9 280X Gaming 3G</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label7" runat="server" Text="Select RAM" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlRAM" runat="server" Visible="False">
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>32</asp:ListItem>
<asp:ListItem>64</asp:ListItem>
<asp:ListItem>128</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label8" runat="server" Text="Select Program" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlProgram" runat="server" Visible="False">
<asp:ListItem>Xara Photo & Graphic 2013</asp:ListItem>
<asp:ListItem>Real-time 3D Character</asp:ListItem>
<asp:ListItem>Autodesk Inventor</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2015</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2014</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2013</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2012</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2011</asp:ListItem>
<asp:ListItem>Autodesk AutoCAD 2010</asp:ListItem>
<asp:ListItem>QuickBooks 2017</asp:ListItem>
<asp:ListItem>QuickBooks !=2017</asp:ListItem>
<asp:ListItem>Visual Studio 2015</asp:ListItem>
<asp:ListItem>Visual Studio 2016</asp:ListItem>
<asp:ListItem>Visual Studio 2017</asp:ListItem>
<asp:ListItem>Visual Studio 2013</asp:ListItem>
<asp:ListItem>Visual Studio 2012</asp:ListItem>
<asp:ListItem>Visual Studio 2011</asp:ListItem>
<asp:ListItem>Visual Studio 2010</asp:ListItem>
<asp:ListItem>Visual Studio 2009</asp:ListItem>
<asp:ListItem>Visual Studio 2014</asp:ListItem>
<asp:ListItem>Office suite</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label9" runat="server" Text="Select Software Install Date" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlSoftInstalDate" runat="server" Visible="False">
<asp:ListItem>JUN 2009</asp:ListItem>
<asp:ListItem>MAY 2010</asp:ListItem>
<asp:ListItem>JUN 2011</asp:ListItem>
<asp:ListItem>DEC 2012</asp:ListItem>
<asp:ListItem>DEC 2013</asp:ListItem>
<asp:ListItem>JAN 2014</asp:ListItem>
<asp:ListItem>JAN 2015</asp:ListItem>
<asp:ListItem>FEB 2015</asp:ListItem>
<asp:ListItem>JUL 2016</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label10" runat="server" Text="Select Software Expire Date" Visible="False"></asp:Label>
<asp:DropDownList ID="ddlSoftExpDate" runat="server" Visible="False">
<asp:ListItem>DEC 2013</asp:ListItem>
<asp:ListItem>DEC 2014</asp:ListItem>
<asp:ListItem>MAY 2015</asp:ListItem>
<asp:ListItem>DEC 2015</asp:ListItem>
<asp:ListItem>JAN 2016</asp:ListItem>
<asp:ListItem>JAN 2017</asp:ListItem>
<asp:ListItem>NOV 2018</asp:ListItem>
<asp:ListItem>DEC 2018</asp:ListItem>
<asp:ListItem>DEC 2019</asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<asp:Panel ID="Panel40" runat="server" Visible="False"></asp:Panel>
<asp:CheckBoxList ID="CheckBoxList20" runat="server"></asp:CheckBoxList>
<asp:Panel ID="Panel50" runat="server" Visible="False"></asp:Panel>
</div>
</form>
</body>
</html>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace VirginiaCollege
{
public partial class Find : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btSubmitUserType_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "IT Admin" )
{
Panel6.Visible = true;
Panel1.Visible = false;
}
else if (DropDownList1.SelectedItem.Text == "Executive Management" )
{
Panel6.Visible = true;
Panel1.Visible = false;
}
else if (DropDownList1.SelectedItem.Text == "Academic Director")
{
Panel7.Visible = true;
Panel1.Visible = false;
}
else if (DropDownList1.SelectedItem.Text == "Teachers")
{
Panel8.Visible = true;
Panel1.Visible = false;
}
else if (DropDownList1.SelectedItem.Text == "Students")
{
Panel8.Visible = true;
Panel1.Visible = false;
}
}
protected void btSubmitUserTypePsWrd_Click(object sender, EventArgs e)
{
if (tbPassword.Text == "Admin")
{
Panel2.Visible = true;
Panel1.Visible = false;
Panel6.Visible = false;
}
}
protected void btSubmitUserTypePsWrd2_Click(object sender, EventArgs e)
{
if (tbPassword2.Text == "Director")
{
Panel3.Visible = true;
Panel1.Visible = false;
Panel7.Visible = false;
}
}
protected void btSubmitUserTypePsWrd3_Click(object sender, EventArgs e)
{
if (tbPassword3.Text == "Student")
{
Panel4.Visible = true;
Panel1.Visible = false;
Panel8.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (cbCity.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label1.Visible = true;
DropDownList2.Visible = true;
}
if (cbComputerType.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label2.Visible = true;
DropDownList3.Visible = true;
}
if (cbDepartment.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label2.Visible = true;
DropDownList3.Visible = true;
}
if (cbRoomNumber.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label3.Visible = true;
DropDownList4.Visible = true;
}
if (cbComputerPosition.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label4.Visible = true;
DropDownList5.Visible = true;
}
if (cbGraphicsCard.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label5.Visible = true;
DropDownList6.Visible = true;
}
if (cbRAM.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label6.Visible = true;
DropDownList7.Visible = true;
}
if (cbProgram.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label7.Visible = true;
DropDownList8.Visible = true;
}
if (cbInstallDate.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label8.Visible = true;
DropDownList9.Visible = true;
}
if (cbExperationDate.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label9.Visible = true;
DropDownList10.Visible = true;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (cbComputerType2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label1.Visible = true;
DropDownList2.Visible = true;
}
if (cbDepartment2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label2.Visible = true;
DropDownList3.Visible = true;
}
if (cbRoomNumber2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label3.Visible = true;
DropDownList4.Visible = true;
}
if (cbGraphicsCard2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label5.Visible = true;
DropDownList6.Visible = true;
}
if (cbRAM2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label6.Visible = true;
DropDownList7.Visible = true;
}
if (cbProgram2.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label7.Visible = true;
DropDownList8.Visible = true;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
if (cbComputerType3.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label1.Visible = true;
DropDownList2.Visible = true;
}
if (cbGraphicsCard3.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label5.Visible = true;
DropDownList6.Visible = true;
}
if (cbRAM3.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label6.Visible = true;
DropDownList7.Visible = true;
}
if (cbProgram3.Checked == true)
{
Panel5.Visible = true;
Panel2.Visible = false;
Label7.Visible = true;
DropDownList8.Visible = true;
}
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Related
I need to display error if user selects "Other" Radio button and leaves it blank or enters wrong data in textbox. once user enters right data error goes away.
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" OnSelectedIndexChanged="radyears_SelectedIndexChanged" Font-Names="Arial" Font-Size="12pt">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" AutoPostBack="True" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
Below is image showing how radiobutton shows with textbox and error message label next to textbox.
Here is image of radiobutton display
##### Here is my Try
if (radyears.SelectedValue == "Other")
{
if (String.IsNullOrEmpty(txtother.Text) || (!double.TryParse(txtother.Text, out years)))
{
lblothererror.Text = "Not Valid Input";
return;
}
else
{
lblothererror.Text = "valid number";
return;
}
Try this code :-
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" Font-Names="Arial" Font-Size="12pt" OnSelectedIndexChanged="radyears_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" AutoPostBack="True" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10" OnTextChanged="txtother_TextChanged"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
and in aspx.cs page
protected void radyears_SelectedIndexChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
lblothererror.Text = "Enter age in Textbox";
}
else
{
lblothererror.Text = "";
}
}
protected void txtother_TextChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
double years = 100;
if (String.IsNullOrEmpty(txtother.Text) || (Convert.ToInt32(txtother.Text) > years))
{
lblothererror.Text = "Invalid";
}
else
{
lblothererror.Text = "valid";
}
}
else
{
lblothererror.Text = "";
}
}
Try this
Here is c# code
protected void radyears_SelectedIndexChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
lblothererror.Text = "Enter value in Textbox please";
}
}
protected void txtother_TextChanged(object sender, EventArgs e)
{
if (radyears.SelectedValue == "Other")
{
double years = 123;//Any Value
if (String.IsNullOrEmpty(txtother.Text) || (!double.TryParse(txtother.Text, out years)))
{
lblothererror.Text = "Not Valid Input";
return;
}
else
{
lblothererror.Text = "valid number";
return;
}
}
else
{
lblothererror.Text = "";
return;
}
}
and here it is
<asp:RadioButtonList ID="radyears" AutoPostBack="true" runat="server" Height="63px" Width="100px" OnSelectedIndexChanged="radyears_SelectedIndexChanged" Font-Names="Arial" Font-Size="12pt">
<asp:ListItem Selected="True" Value="15">15 Years</asp:ListItem>
<asp:ListItem Value="30">30 Years</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txtother" runat="server" OnTextChanged="txtother_TextChanged" Font-Names="Arial" Font-Size="12pt" Width="150px" MaxLength="10"></asp:TextBox>
<asp:Label ID="lblothererror" runat="server" Font-Names="Arial" Font-Size="11pt" ForeColor="Red"></asp:Label>
I have the following Telerik RadGrid, which I'm using in C#:
<MasterTableView Width="100%" EditMode= "InPlace" ClientDataKeyNames="menuID" CommandItemDisplay= "Top">
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" UniqueName="Name"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="Type" HeaderText="Type">
<ItemTemplate>
<asp:TextBox ID="Type" Text='<%# DataBinder.Eval(Container.DataItem, "Type") %>' runat="server"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="List" HeaderText="List">
<ItemTemplate>
<asp:CheckBox ID="List" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "List") %>' />
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="loadAtStart" HeaderText="loadAtStart">
<ItemTemplate>
<asp:CheckBox ID="loadAtStart" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "loadAtStart") %>' />
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
The grid is populated with data, and working normally when editing the data.
But when I click on the Add New Record button provided by Telerik, then an empty row is added without any TextBox or CheckBox in the columns to edit in the new Row added. It's just an empty row. I presume that I have to create the controls dynamically in the called ItemDataBound event, but I didn't manage to find the actual code for this.
How do I solve this?
Please try with the below code snippet.
ASPX
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
AllowFilteringByColumn="true" AllowPaging="true" OnItemCommand="RadGrid1_ItemCommand">
<PagerStyle AlwaysVisible="true" />
<MasterTableView DataKeyNames="UniqueID" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Save All" OnClick="Button1_Click" />
ASPX.CS
public partial class aaaa : System.Web.UI.Page
{
public List<Employee> lstEmployee
{
get
{
if (Session["lstEmployee"] != null)
{
return (List<Employee>)Session["lstEmployee"];
}
else
{
return new List<Employee>();
}
}
set
{
Session["lstEmployee"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Employee> list = new List<Employee>();
Employee obj = new Employee();
obj.ID = 1;
obj.Name = "Name1";
obj.UniqueID = Guid.NewGuid();
list.Add(obj);
obj = new Employee();
obj.ID = 2;
obj.Name = "Name2";
obj.UniqueID = Guid.NewGuid();
list.Add(obj);
lstEmployee = list;
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = lstEmployee;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
saveAllData();
lstEmployee.Insert(0, new Employee() { UniqueID = Guid.NewGuid() });
e.Canceled = true;
RadGrid1.Rebind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
saveAllData();
}
protected void saveAllData()
{
//Update Session
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
Guid UniqueID = new Guid(item.GetDataKeyValue("UniqueID").ToString());
Employee emp = lstEmployee.Where(i => i.UniqueID == UniqueID).First();
emp.Name = (item.FindControl("TextBox1") as TextBox).Text;
}
}
}
public class Employee
{
public Guid UniqueID { get; set; }
public int ID { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public int weeknumber { get; set; }
}
I have modified the parameters according to my requirement and also included all CURD operations.
ASPX Page
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource"
AllowFilteringByColumn="true" AllowPaging="true" OnItemCommand="RadGrid1_ItemCommand">
<PagerStyle AlwaysVisible="true" />
<MasterTableView DataKeyNames="UniqueID" CommandItemDisplay="Top" AutoGenerateColumns="false" >
<Columns>
<telerik:GridEditCommandColumn ButtonType="FontIconButton" />
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" ButtonType="FontIconButton" UniqueName="DeleteColumn" />
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="Sku" UniqueName="Sku" HeaderText="Sku">
<ItemTemplate>
<asp:Label ID="TxtSku" runat="server" Text='<%# Eval("Sku") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TxtSku" runat="server" Text='<%# Eval("Sku") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TxtSku" runat="server" Text='<%# Eval("Sku") %>'></asp:TextBox>
</InsertItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Save All" OnClick="Button1_Click" />
<telerik:RadAjaxManager runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
<telerik:AjaxUpdatedControl ControlID="Button1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
CS Code
public List<ItemDetail> ItemDetail
{
get
{
if (Session["ItemDetail"] != null)
{
return (List<ItemDetail>)Session["ItemDetail"];
}
else
{
return new List<ItemDetail>();
}
}
set
{
Session["ItemDetail"] = value;
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = ItemDetail;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
}
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
var item = (GridEditFormItem)e.Item;
var txtReferenceNumber = (TextBox)item.FindControl(id: "TxtSku");
var val = txtReferenceNumber.Text;
ItemDetail.Insert(0, new ItemDetail() { UniqueID = Guid.NewGuid(), Sku = val, ID = Convert.ToInt32(22) });
item.Edit = false;
RadGrid1.Rebind();
}
if (e.CommandName == RadGrid.UpdateCommandName)
{
var item = (GridEditFormItem)e.Item;
var txtReferenceNumber = (TextBox)item.FindControl(id: "TxtSku");
string requestId = item.GetDataKeyValue(keyName: "UniqueID").ToString().Trim();
Guid RequestIndentifier = Guid.Parse(requestId);
var val = txtReferenceNumber.Text;
var itemFind = ItemDetail.Where(x => x.UniqueID == RequestIndentifier);
itemFind.FirstOrDefault().Sku = val;
item.Edit = false;
RadGrid1.Rebind();
}
if (e.CommandName == RadGrid.DeleteCommandName)
{
var item = (GridDataItem)e.Item;
string requestId = item.GetDataKeyValue(keyName: "UniqueID").ToString().Trim();
Guid RequestIndentifier = Guid.Parse(requestId);
ItemDetail.RemoveAll(x => x.UniqueID == RequestIndentifier);
RadGrid1.Rebind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SaveAllData();
}
private void SaveAllData()
{
//Update Session
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
Guid UniqueID = new Guid(item.GetDataKeyValue("UniqueID").ToString());
ItemDetail emp = ItemDetail.Where(i => i.UniqueID == UniqueID).First();
emp.Sku = (item.FindControl("TxtSku") as TextBox).Text;
}
}
}
public class ItemDetail
{
public Guid UniqueID { get; set; }
public int ID { get; set; }
public string Sku { get; set; }
}
if (!Page.IsPostBack)
{
List<ItemDetail> list = new List<ItemDetail>();
ItemDetail obj = new ItemDetail
{
ID = 1,
Sku = "Name1",
UniqueID = Guid.NewGuid()
};
list.Add(obj);
obj = new ItemDetail();
obj.ID = 2;
obj.Sku = "Name2";
obj.UniqueID = Guid.NewGuid();
list.Add(obj);
ItemDetail = list;
}
Hope this would help you :-)
I'm not really a fan of any of these solutions because they require the use of Session. Session has it's place but I believe it's used more as a crutch.
You're already sending the RadGrid information back to the server-side via ViewState due to the PostBack so why not use it's information instead of relying on an in-memory store.
Example of Adding and Removing an item from a Grid. Yes, it does require iterating items to rebuild a List but it's an alternative to Session so I believe it has merit.
protected void addValueToRecentTagList(string text)
{
List<string> items = new List<string>();
foreach(GridDataItem row in RadGridNewTags.Items)
items.Add(row["tag"].Text);
items.Add(text);
RadGridNewTags.DataSource = items;
RadGridNewTags.DataBind();
}
protected void removeValueFromRecentTagList(string text)
{
List<string> items = new List<string>();
bool rebind = false;
foreach (GridDataItem row in RadGridNewTags.Items)
{
if (row["tag"].Text == text)
rebind = true;
else
items.Add(row["tag"].Text);
}
if (rebind)
{
RadGridNewTags.DataSource = items;
RadGridNewTags.DataBind();
}
}
You have to insert a control in the EditItemTemplate to display in Edit or Insert mode.
Or you can add an InsertItem Template and place a control in there:
<telerik:GridTemplateColumn UniqueName="loadAtStart" HeaderText="loadAtStart">
<ItemTemplate>
<asp:CheckBox ID="loadAtStart" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "loadAtStart") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="cbxEditLoadAtStart" runat="server" Checked='<%# Bind("loadAtStart") %>' />
</EditItemTemplate>
<InsertItemTemplate>
<asp:CheckBox ID="cbxInsertLoadAtStart" runat="server" />
</InsertItemTemplate>
</telerik:GridTemplateColumn>
I have a simple formview and simple modelbinding in webform:
<asp:FormView ID="frm" ItemType="SabaDoor2.Models.Content" SelectMethod="frm_GetItem" UpdateMethod="frm_UpdateItem" DataKeyNames="Id" runat="server">
<ItemTemplate>
<fieldset>
<legend>
<asp:Label ID="lblName" Text='<%# Item.Name %>' runat="server"></asp:Label>
</legend>
<p>
<label>descripion :</label>
<asp:Label ID="lblDescription" Text='<%# Item.Description %>' runat="server"></asp:Label>
</p>
<p>
<asp:Button ID="btnEdit" Text="edit" CommandName="Edit" runat="server" />
</p>
</fieldset>
</ItemTemplate>
<EditItemTemplate>
<fieldset>
<legend>
<asp:Label ID="lblName" Text='<%# Item.Name %>' runat="server"></asp:Label>
</legend>
<p>
<label>description :</label>
<asp:TextBox ID="txt" Text='<%# Item.Description %>' runat="server" ></asp:TextBox>
</p>
<p>
<asp:Button CommandName="Update" ValidationGroup="mainPropertyGroup" runat="server" ID="btnUpdate" Text="update" />
<asp:Button CommandName="Cancel" ValidationGroup="mainPropertyGroup" runat="server" ID="btnCancel" Text="cancel" />
</p>
</fieldset>
<br />
</EditItemTemplate>
</asp:FormView>
and in code:
Models.Model1Container _db = new Models.Model1Container();
protected void Page_Load(object sender, EventArgs e)
{
bindEvents();
lblResult.ForeColor = System.Drawing.Color.Green;
lblResult.Text = "";
if (!IsPostBack)
{
}
else
{
}
}
private void bindEvents()
{
frm.ItemUpdated += frm_ItemUpdated;
}
void frm_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
{
if (e.Exception == null)
{
lblResult.ForeColor = System.Drawing.Color.Green;
lblResult.Text = "done!";
}
else
{
lblResult.ForeColor = System.Drawing.Color.Red;
lblResult.Text = "error:" + e.Exception.Message;
e.KeepInEditMode = true;
}
}
public SabaDoor2.Models.Content frm_GetItem([System.Web.ModelBinding.QueryString("Id")]int? Id)
{
return _db.Contents.Find(Id);
}
// The id parameter name should match the DataKeyNames value set on the control
public void frm_UpdateItem(int Id)
{
SabaDoor2.Models.Content item = null;
item = _db.Contents.Find(Id);
if (item == null)
{
// The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", Id));
return;
}
var result = TryUpdateModel(item);
if (ModelState.IsValid)
{
_db.SaveChanges();
}
}
public override void Dispose()
{
_db.Dispose();
base.Dispose();
}
tryUpdateModel return true but my model(description field) doesn't update
:(
I find out logical error:
i have to initialize BindItem.Name property instd of item.Name
Text='<%# BindItem.Description %>'
What is up with my spacing here? When the labels contain text the spacing is fine but then they are empty they have white space between each label. Why is extra space being added when the labels contain empty text?
With text in labels (what I want it to look like):
With no text in labels (how I do not want it to look like):
On the C# code behind side:
// On page load
for (int i = 1; i < 10; i++)
{
string ID = i.ToString();
PopulateLastNameLabel(ID);
}
protected void PopulateLastNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Height = 20;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Red;
lbl.ID = "lastname_" + ID;
pnlLastNameLabel.Controls.Add(lbl);
}
On the ASP.NET side:
<asp:Table ID="tblDisplayTable" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNumberLabel" runat="server" Width="80px"></asp:Panel>
</asp:TableCell>
<asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Panel ID="pnlPrizeDropDownList" runat="server" Width="130px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlNickNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNicknameTextBox" runat="server" Width="125px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlFirstNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlLastNameLabel" runat="server" Width="70px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlEmailAddressLabel" runat="server" Width="140px"></asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlAddButton" runat="server" Width="40px"></asp:Panel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
If I understand you question correctly, you need the following css (remove height from code behind).
The problem each control is in own table cell, so they won't horizontal align properly. So you need to set height explicitly for each control.
<style type="text/css">
td div { margin-right: 5px; }
td div input {border: 1px solid #828282; height: 21px; }
td div span { height: 25px; line-height: 25px; }
</style>
<asp:Table ID="tblDisplayTable" runat="server" CellPadding="0" CellSpacing="0">
<asp:TableRow>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNumberLabel" runat="server" Width="80px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell HorizontalAlign="Center" VerticalAlign="Middle">
<asp:Panel ID="pnlPrizeDropDownList" runat="server" Width="130px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlNickNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlPrizeNicknameTextBox" runat="server" Width="125px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlFirstNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlLastNameLabel" runat="server" Width="70px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlEmailAddressLabel" runat="server" Width="140px">
</asp:Panel>
</asp:TableCell>
<asp:TableCell>
<asp:Panel ID="pnlAddButton" runat="server" Width="40px">
</asp:Panel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
string ID = i.ToString();
TextBoxLabel(ID);
PopulatePrizeNicknameLabel(ID);
PopulateFirstNameLabel(ID);
PopulateLastNameLabel(ID);
}
}
protected void TextBoxLabel(string ID)
{
TextBox lbl = new TextBox();
lbl.Width = 65;
lbl.Text = "";
lbl.ID = "TextBox_" + ID;
lbl.Text = ID;
pnlNickNameLabel.Controls.Add(lbl);
}
protected void PopulatePrizeNicknameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 125;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Green;
lbl.ID = "PrizeNickname_" + ID;
lbl.Text = ID;
pnlPrizeNicknameTextBox.Controls.Add(lbl);
}
protected void PopulateLastNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Red;
lbl.ID = "lastname_" + ID;
lbl.Text = ID;
pnlLastNameLabel.Controls.Add(lbl);
}
protected void PopulateFirstNameLabel(string ID)
{
Label lbl = new Label();
lbl.Width = 70;
lbl.Text = "";
lbl.BackColor = System.Drawing.Color.Blue;
lbl.ID = "firstname_" + ID;
lbl.Text = ID;
pnlFirstNameLabel.Controls.Add(lbl);
}
I prefer creating controls one row at a time instead of one column at a time, but that is not OP.
I have a gridview in an update panel and it is working fine. However on the click of the edit button I want to open the edit form. But the edit button click is not working. When i debug it, the method is working fine however the page doesn't postback. I have tried using triggers but to no avail.
<asp:UpdatePanel ID="upnlgrid" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="gvGroupMaster" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanging="gvGroupMaster_SelectedIndexChanging" OnSelectedIndexChanged="gvGroupMaster_SelectedIndexChanged" OnRowDataBound="gvGroupMaster_RowDataBound" AllowSorting="true" OnPageIndexChanging="gvGroupMaster_PageIndexChanging" OnSorting="gvGroupMaster_Sorting"
ShowHeader="True" CssClass="tabledata" Width="100%" DataKeyNames="igroup_id">
<AlternatingRowStyle CssClass="pointer" />
<RowStyle CssClass="even pointer" />
<HeaderStyle CssClass="headings" />
<Columns>
<asp:TemplateField HeaderText="Sort Order" ItemStyle-CssClass="colmn1" SortExpression="isort_position" >
<ItemTemplate>
<%-- <asp:ImageButton ID="btnSort" OnClick="btnSortClick" imageurl="../images/order-sort-btnup.png" runat="server"></asp:ImageButton>--%>
<asp:Button ID="btnSort" class="sortord pointer" runat="server" OnClick="btnSortClick" ></asp:Button>
<asp:Button ID="btnSortDown" class="sortorddown pointer" runat="server" OnClick="btnSortDownClick"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Group Name" SortExpression="strgroup_name" ItemStyle-CssClass="colmn2" >
<ItemTemplate>
<asp:Label ID="lblGroupName" runat="server"
Text='<%# Bind("strgroup_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Short Name" SortExpression="strgroup_sname" ItemStyle-CssClass="colmn3" >
<ItemTemplate>
<asp:Label ID="lblShortName" runat="server"
Text='<%# Bind("strgroup_sname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Under" SortExpression="iparent_id" ItemStyle-CssClass="colmn4">
<ItemTemplate>
<asp:Label ID="lblUnder" runat="server"
Text='<%# Bind("strunder") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nature Of Group" SortExpression="strnature_of_group" ItemStyle-CssClass="colmn5">
<ItemTemplate>
<asp:Label ID="lblNatureOfGroup" runat="server"
Text='<%# Bind("strnature_of_group") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Affect Gross Profit" SortExpression="straffect_gross_profits" ItemStyle-CssClass="colmn6">
<ItemTemplate>
<asp:Label ID="lblAffectGrossProfits" runat="server" Text='<%# Bind("straffect_gross_profits") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nett DrCr Report" SortExpression="strnett_drcr_report" ItemStyle-CssClass="colmn7">
<ItemTemplate>
<asp:Label ID="lblNettDrcrReport" runat="server"
Text='<%# Bind("strnett_drcr_report") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created By" SortExpression="icreated_by" ItemStyle-CssClass="colmn8">
<ItemTemplate>
<asp:Label ID="lblCreatedBy" runat="server"
Text='<%# Bind("strcreated_by") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created On" SortExpression="dtcreated_on" ItemStyle-CssClass="colmn9">
<ItemTemplate>
<asp:Label ID="lblCreatedOn" runat="server"
Text='<%# Bind("dtcreated_on") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Updated On" SortExpression="dtupdated_on" ItemStyle-CssClass="colmn10">
<ItemTemplate>
<asp:Label ID="lbLastUpdatedOn" runat="server"
Text='<%# Bind("dtupdated_on") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="colmn11">
<ItemTemplate>
<asp:Button id="btnInfo" runat="server" class="infoicon" Text='<%# Eval("igroup_id") %>' OnClick="infoclick"/>
<asp:Button id="btnEdit" runat="server" class="editicon" CausesValidation="false" Text='<%# Eval("igroup_id") %>' OnClick="editclick"/>
<asp:Button id="btnDelete" runat="server" class="deleteicon" Text='<%# Eval("igroup_id") %>' OnClick="deleteclick"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
codebehind for edit click
protected void editclick(object sender, EventArgs e)
{
try
{
//int rindex = (((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex;
Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");
edit(EditButton.Text.ToString());
this.Session["edit"] = EditButton.Text.ToString();
}
catch
{
}
}
protected void edit(string editid)
{
try
{
GroupMasterClass gm = new GroupMasterClass();
CompanyMasterClass co = new CompanyMasterClass();
gm.igroup_id = Convert.ToInt32(editid);
ResultClass objres = gm.fn_GetGroupByIdForEdit();
if (objres.bStatus)
{
eslist<GroupMasterClass> OBJLIST = objres.objData as eslist<GroupMasterClass>;
if (OBJLIST.Count > 0)
{
co.strcompany_code = Request.Cookies["userinfo"]["companycode"].ToString();
ResultClass objress = co.fn_GetNameNumberStyle();
if (objress.bStatus)
{
eslist<CompanyMasterClass> OBJLISTS = objress.objData as eslist<CompanyMasterClass>;
if (OBJLISTS.Count > 0)
{
addfrm.Visible = true;
gridmain.Visible = false;
if (OBJLISTS[0].strname_style.ToString() == "PC")
{
txtGroupName.Text = misc.ToTitleCase(OBJLIST[0].strgroup_name);
txtGroupSname.Text = misc.ToTitleCase(OBJLIST[0].strgroup_sname);
}
if (OBJLISTS[0].strname_style.ToString() == "UC")
{
txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
txtGroupName.Style.Add("text-transform", "uppercase");
txtGroupSname.Style.Add("text-transform", "uppercase");
}
if (OBJLISTS[0].strname_style.ToString() == "UG")
{
txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
}
}
}
txtUnder.Text = OBJLIST[0].strunder;
txtNotes.Text = OBJLIST[0].strnotes;
for (int i = 0; i < OBJLIST.Count; i++)
{
CompanyMasterClass cm = new CompanyMasterClass();
string p = OBJLIST[0].strcompany_code.ToString();
string t = string.Empty;
string code = string.Empty;
int count = 0;
string[] availcompanycode = p.Split(',');
foreach (string k in availcompanycode)
{
t = k.ToString();
code += "'" + t.ToString() + "'" + ",";
count++;
}
cm.strcompany_code = code.TrimEnd(',');
ResultClass objrest = cm.fn_GetCompanyListByCompanycode();
if (objres.bStatus)
{
eslist<CompanyMasterClass> OBJLISTS = objrest.objData as eslist<CompanyMasterClass>;
if (OBJLISTS.Count > 0)
{
// listboxsource.Items.Clear();
listboxdestination.DataTextField = "strcompany_name";
listboxdestination.DataValueField = "strcompany_code";
listboxdestination.DataSource = OBJLISTS;
listboxdestination.DataBind();
}
}
ListItem itemnature = new ListItem();
if (OBJLIST[i].strnature_of_group == "A")
itemnature.Text = "Assets";
else if (OBJLIST[i].strnature_of_group == "E")
itemnature.Text = "Expenses";
else if (OBJLIST[i].strnature_of_group == "I")
itemnature.Text = "Income";
else if (OBJLIST[i].strnature_of_group == "L")
itemnature.Text = "Liabilities";
// itemnature.Value = OBJLIST[i].igroup_id.ToString();
ddlNature.Items.Add(itemnature);
ListItem itemaffects = new ListItem();
if (OBJLIST[i].straffect_gross_profits == "N")
itemaffects.Text = "No";
else if (OBJLIST[i].straffect_gross_profits == "Y")
itemaffects.Text = "Yes";
//itemaffects.Value = OBJLIST[i].igroup_id.ToString();
ddlGrossProfit.Items.Add(itemaffects);
ListItem itemnett = new ListItem();
if (OBJLIST[i].strnett_drcr_report == "N")
itemnett.Text = "No";
else if (OBJLIST[i].strnett_drcr_report == "Y")
itemnett.Text = "Yes";
// itemnett.Value = OBJLIST[i].igroup_id.ToString();
ddlNett.Items.Add(itemnett);
ListItem itemlock = new ListItem();
if (OBJLIST[i].strlock_status == "N")
itemlock.Text = "No";
else if (OBJLIST[i].strlock_status == "Y")
itemlock.Text = "Yes";
// itemnett.Value = OBJLIST[i].igroup_id.ToString();
ddlNett.Items.Add(itemlock);
}
}
}
}
catch
{
}
}
Any ideas?
Thanks,
Try using Button editbtn = (Button)sender; Rather than Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");