i am developing webform with gridview. I have a problem, the value of checkbox doesn't save in the table. I've tried everything nothing is working. After i press a button, value doesn't store.
And as you can see in my code, i don't use id for unidentified of each particular row, instead id i use foreach
protected void Button_Submit_Onclick(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView2.Rows)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["TestDeductionsConnectionString2"].ToString();
bool private1 = (row.FindControl("CheckBox1") as CheckBox).Checked;
SqlCommand cmd = new SqlCommand("insert into DetailCosts(private) values(#private1)", con);
if (private1 == true)
{
cmd.Parameters.Add(new SqlParameter("#private1", SqlDbType.Bit));
cmd.Parameters["#private1"].Value = 1;
//cmd.Parameters.Add("#private1", SqlDbType.Bit).Value = 1;
}
else
{
cmd.Parameters.Add(new SqlParameter("#private1", SqlDbType.Bit));
cmd.Parameters["#private1"].Value = 0;
//cmd.Parameters.Add("#private1", SqlDbType.Bit).Value = 0;
}
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}}
and there is a code with my Gridview:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataKeyNames="recordid">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="recordid" HeaderText="recordid" SortExpression="recordid">
</asp:BoundField>
<asp:BoundField DataField="Employee" HeaderText="Employee" SortExpression="Employee">
</asp:BoundField>
<asp:BoundField DataField="mesec" HeaderText="Month" SortExpression="mesec">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="godina" HeaderText="Year" SortExpression="godina">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="CallDate" HeaderText="Call Date" SortExpression="CallDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="PhoneType" HeaderText="Phone Type" SortExpression="PhoneType">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="land" HeaderText="Land" SortExpression="land">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="number" HeaderText="Number" SortExpression="number">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Minutes" HeaderText="Minutes" SortExpression="Minutes">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Costs" HeaderText="Costs" SortExpression="Costs">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="privateCost" HeaderText="Private Costs" SortExpression="privateCost">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="Private" SortExpression="private" >
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("private") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("private") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Komentar" HeaderText="Commnet" SortExpression="Komentar">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Related
protected void CovidSelfDecleartionDeatils_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
ShowallRecord();
if (e.CommandArgument != "")
{
int Index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName=="Select")
{
DataTable dt_main = new DataTable();
dt_main = (DataTable)ViewState["ReportData"];
GridViewRow clickedRow = CovidSelfDecleartionDeatils.Rows[Index];
Session["Filepath"] = clickedRow.Cells[9].Text;
//Session["Filepath"] = CovidSelfDecleartionDeatils.Rows[Index].FindControl("FilePath");
Session["Filepath1"] = CovidSelfDecleartionDeatils.DataKeys[Index]["Filepath"].ToString();
string filepath = Session["Filepath"].ToString();
//DataGridViewSelectedRowCollection rows = dataGridView1.SelectedRows;
//string val = (string)rows[2].Cells["Late_Time"].Value;
}
}
}
catch
{
}
}
<asp:GridView ID="CovidSelfDecleartionDeatils" runat="server" DataKeyNames="EmployeeCode" AutoGenerateColumns="False"
BackColor="#333333" CellPadding="5" CellSpacing="3" ForeColor="Black" Width="100%" Height="300px" OnRowCommand="CovidSelfDecleartionDeatils_RowCommand" >
<Columns>
<%-- <asp:BoundField DataField="InitiateMPPId" HeaderText="InitiateMPPId" >
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>--%>
<asp:BoundField DataField="EmployeeCode" HeaderText="EmployeeCode" ItemStyle-HorizontalAlign="Left" Visible="false"
HeaderStyle-HorizontalAlign="Left" ControlStyle-BorderStyle="None" ItemStyle-CssClass="per10"
HeaderStyle-CssClass="header-center">
</asp:BoundField>
<%-- <asp:BoundField DataField="EmployeeCode" HeaderText="EmployeeCode" ItemStyle-HorizontalAlign="Left" Visible="false"
HeaderStyle-HorizontalAlign="Left" ControlStyle-BorderStyle="None" ItemStyle-CssClass="per10"
HeaderStyle-CssClass="header-center">
</asp:BoundField>--%>
<asp:BoundField DataField="EmpName" HeaderText="Employee" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" >
</asp:BoundField>
<asp:BoundField DataField="Decleartion_Date" HeaderText="Date Decleartion" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:dd-MM-yyyy}" >
</asp:BoundField>
<asp:BoundField DataField="Ferver" HeaderText="Ferver" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Cough" HeaderText="Cough" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"/>
<asp:BoundField DataField="Breathlessness" HeaderText="Breathlessness" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"/>
<asp:BoundField DataField="OtherDiseases" HeaderText="OtherDiseases" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-CssClass="per50" ItemStyle-Height="25" HeaderStyle-Height="25" HeaderStyle-CssClass="header-center" HeaderStyle-Wrap="true"/>
<asp:BoundField DataField="FileName" HeaderText="FileName" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-CssClass="per50" ItemStyle-Height="25" HeaderStyle-Height="25" HeaderStyle-CssClass="header-center" HeaderStyle-Wrap="true" Visible="false" />
<asp:BoundField DataField="DeclarationID" HeaderText="DeclarationID" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-CssClass="per50" ItemStyle-Height="25" HeaderStyle-Height="25" HeaderStyle-CssClass="header-center" HeaderStyle-Wrap="true" Visible="false" />
<asp:BoundField DataField="FilePath" HeaderText="FilePathfordownload" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-CssClass="per50" ItemStyle-Height="25" HeaderStyle-Height="25" HeaderStyle-CssClass="header-center" HeaderStyle-Wrap="true" Visible="false" />
<asp:BoundField DataField="ContactwithCovid" HeaderText="Incontact with covid patient Last(14) days" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-CssClass="per50" ItemStyle-Height="25" HeaderStyle-Height="25" HeaderStyle-Width="15%" HeaderStyle-CssClass="header-center" HeaderStyle-Wrap="true"/>
<%--<asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="btn_delete_record"
Width="20px" Height="20px" runat="server" ImageUrl="~/Content/Images/NewIcons/PDF.png" />
</ItemTemplate>
</asp:TemplateField>--%>
<asp:ButtonField CommandName="Select" ControlStyle-CssClass="button" ButtonType="Image" ImageUrl="~/Content/Images/NewIcons/PDF.png"
ItemStyle-Width="5px" HeaderText="Download Attachment" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="TravelDate" HeaderText="TravelDate" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:dd-MM-yyyy}" />
<asp:BoundField DataField="StateName" HeaderText="StateName" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#5e5d5d" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="Gray" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
what wrong in my showing excetion " Object reference is not set" when i am saving value in session
remove visible=false and define new css class like
.donotshow { display: none; }
and add it HeaderStyle-CssClass and ItemStyle-CssClass
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CssClass="table-bordered table-hover table-responsive table" BackColor="White" BorderColor="White" CellPadding="3" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" >
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowSelectButton="True" ControlStyle-CssClass="accept" SelectText="Accept" ControlStyle-ForeColor="Green" >
<ControlStyle CssClass="accept" ForeColor="Green"></ControlStyle>
</asp:CommandField>
<asp:CommandField ShowSelectButton="True" ControlStyle-CssClass="reject" SelectText="Reject" ControlStyle-ForeColor="Red" >
<ControlStyle CssClass="reject" ForeColor="Red"></ControlStyle>
</asp:CommandField>
<asp:BoundField HeaderText="Status" />
<asp:BoundField DataField="first_name" HeaderText="First name" SortExpression="first_name" />
<asp:BoundField DataField="last_name" HeaderText="Last name" SortExpression="last_name" />
<asp:BoundField DataField="c_email" HeaderText="Email" SortExpression="c_email" />
<asp:BoundField DataField="contact" HeaderText="Contact" SortExpression="contact" />
<asp:BoundField DataField="licenseno" HeaderText="License no" SortExpression="licenseno" />
<asp:BoundField DataField="v_name" HeaderText="Vehicle name" SortExpression="v_name" />
<asp:BoundField DataField="v_company" HeaderText="Company" SortExpression="v_company" />
<asp:BoundField DataField="v_plate" HeaderText="Plate no" SortExpression="v_plate" />
<asp:BoundField DataField="wheeler" HeaderText="Wheeler" SortExpression="wheeler" />
<asp:BoundField DataField="damage_Details" HeaderText="Damage details" SortExpression="damage_Details" />
<asp:BoundField DataField="street" HeaderText="Street" SortExpression="street" />
<asp:BoundField DataField="landmark" HeaderText="Landmark" SortExpression="landmark" />
<asp:BoundField DataField="pincode" HeaderText="Pincode" SortExpression="pincode" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#752c82" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Code behind:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.SelectedRow.Cells[2].Text = "Accepted";
string msg = "ACCEPTED";
Session["c_email"] = GridView1.SelectedRow.Cells[5].Text;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
string insert = "insert into Status values(#email,#c_email,#status)";
SqlCommand cmd = new SqlCommand(insert, con);
cmd.Parameters.AddWithValue("#c_email", Session["c_email"].ToString());
cmd.Parameters.AddWithValue("#email", Session["mechanic"].ToString());
cmd.Parameters.AddWithValue("#status", msg.ToString());
cmd.ExecuteNonQuery();
Label1.Text = "You need to reach the customer within one hour and provide the needful service.";
con.Close();
}
I have a grid view that contains two command fields with 2 selection button. I want the button as Accept and Reject on my page. But I am unable to find out how to code it's working.
I have coded for one command field on selectedIndexChanged but how to code for the second command field. Please help me out.
I have a grid with several data columns and a column with check boxes. There is a column called app Number which contains numbers. Now I want to select number in the checked rows and put them into an array. How can I do it?
Here is the code I have done up to now.
<asp:GridView ID="gvAppeals" runat="server" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
Width="665px" AutoGenerateColumns="False" OnSelectedIndexChanged="gvAppeals_SelectedIndexChanged1"
AllowPaging="True" PageSize="10" OnPageIndexChanging="gvAppeals_PageIndexChanging" OnRowDataBound="gvAppeals_RowDataBound">
<Columns>
<asp:BoundField DataField="App_no" HeaderText="APP NO">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="EMP_FULLNAME" HeaderText="FULL NAME">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="EMP_NIC_NO" HeaderText="NIC">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="EMP_BIRTHDAY" HeaderText="BIRTH DATE" DataFormatString="{0:yyyy-MM-dd}">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Font-Size="Small" HorizontalAlign="Left" VerticalAlign="Middle" />
</asp:BoundField>
<asp:TemplateField>
<%--<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" AutoPostBack="true" />
</HeaderTemplate>--%>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="Black" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
C# code
protected void btnConfirm_Click(object sender, EventArgs e)
{
//DataSet ds = new DataSet();
int[] numbers;
numbers = new int[gvAppeals.Rows.Count];
int noOfRowsChecked = 0;
foreach (GridViewRow row in gvAppeals.Rows)
{
int rowIndex = row.RowIndex;
CheckBox chkrow = (CheckBox)row.FindControl("chkSelect");
if (chkrow.Checked == true)
{
numbers[noOfRowsChecked] = Int32.Parse(gvAppeals.DataKeys[rowIndex]["App_no"].ToString());
noOfRowsChecked++;
}
//update the dept by checking the selected appeal numbers
if (noOfRowsChecked > 0)
{
for (int i = 0; i < numbers.Length; i++)
{
int appNo = numbers[i];
dba.confirmAppeal(appNo);
}
}
else
{
WebMsgBox.Show("Please select an application to confirm");
}
}
}
Just a gentle reminder that you need to subtract one (-1) on your indexing. That's probably the reason you're getting System.ArgumentOutOfRangeException.
There are no DataKeys defined in the GridView, to it will always be out of range. Add the DataKeyNames property to the GridView.
<asp:GridView ID="gvAppeals" runat="server" DataKeyNames="App_no" >
I have a gridview with paging function.
the code below is my aspx code for gridview.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None" Width="768px" CellPadding="4" ForeColor="#333333" OnRowDeleting="OnRowDeleting" AllowPaging="True" PageSize="20" OnPageIndexChanging="gridView_PageIndexChanging" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="SAP No" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click"
Text='<%#Eval("SAPNO") %>' runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PARTNO" HeaderText="Part No" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="10%">
</asp:BoundField>
<asp:BoundField DataField="PARTDESC" HeaderText="Description" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="20%">
</asp:BoundField>
<asp:BoundField DataField="MINQTY" HeaderText="Min Qty" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="5%">
</asp:BoundField>
<asp:BoundField DataField="QOH" HeaderText="QOH" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="5%">
</asp:BoundField>
<asp:BoundField DataField="CATEGORY" HeaderText="Category" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="20%">
</asp:BoundField>
<asp:BoundField DataField="EQUIPMENT" HeaderText="Equipment" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="20%">
</asp:BoundField>
<asp:CommandField ShowDeleteButton="true" ButtonType="Image" DeleteImageUrl="Image/delete.JPG" ControlStyle-Height="20px" ControlStyle-Width="50px" HeaderText="Delete">
<HeaderStyle Width="10%" HorizontalAlign="Left" /></asp:CommandField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="<--" PreviousPageText="<" NextPageText=">" LastPageText="-->" />
<PagerStyle HorizontalAlign="Center" BackColor="White" />
</asp:GridView>
At the back end code, i tried to retrieve the first column and specific rows but it throw me empty. the code below is how i retrieve.
int index = Convert.ToInt32(e.RowIndex);
string sapNo1 = GridView1.Rows[index].Cells[0].Text;
string partNo = GridView1.Rows[index].Cells[1].Text;
string partDesc = GridView1.Rows[index].Cells[3].Text;
I try to show all the value for sapNo1, it throw me blank but for partNo it will show the data in the gridview.
anyone has any idea about this?
I am really appreciate your help and comment!
As your first column is a linkbutton so retrieve that as it is then find the value.
string sapNo1 = GridView1.Rows[index].Cells[0].Text; // wrong code to retrieve data from linkbutton in a gridview
Modify this as :
LinkButton linkbtn =(LinkButton)GridView1.Rows[index].FindControl("LinkButton1");
string sapNo1 = linkbtn.Text;
or
string sapNo1 =(GridView1.Rows[index].FindControl("LinkButton1") as LinkButton).Text;
You can't get the controls properties present inside TemplateField like that, you need to find the control like this:-
LinkButton LinkButton1 = (LinkButton)GridView1.Rows[index].Cells[0]
.FindControl("LinkButton1");
After this you can simply fetch the properties of this control:-
string sapNo1 = LinkButton1.Text;
you can get the link button description by the below code
protected void Link_Button_Command(object sender, CommandEventArgs e)
{
try
{
LinkButton button = (LinkButton)sender;
string name = button.ToString();
}
catch (Exception ex)
{
lbl_message.Text = ex.Message;
}
}
I set two Gridview in one page. one's selected index changed event's load another event. But 2nd grid's selectedindexchanged event goes on first's selectedindexchanged event. What can I do? My function name was correct. Not conflicting any other.
Here my asp code :
<asp:GridView ID="gdv" runat="server"
AutoGenerateColumns="False" onrowdatabound="gdv_RowDataBound"
onselectedindexchanged="gdv_SelectedIndexChanged" AllowPaging="True"
Width="100%" onpageindexchanging="gdv_PageIndexChanging">
<Columns>
<asp:BoundField DataField="Sl" HeaderStyle-HorizontalAlign="Center"
HeaderText="SL #" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="SalesOrderNo" HeaderStyle-HorizontalAlign="Left"
HeaderText="Order No" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="SectionID" HeaderStyle-HorizontalAlign="Left"
HeaderText="Section Id" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="SectionName" HeaderStyle-HorizontalAlign="Left"
HeaderText="Section Name" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OutletID" HeaderStyle-HorizontalAlign="Left"
HeaderText="Outlet Id" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OutletName" HeaderStyle-HorizontalAlign="Left"
HeaderText="outlet Name" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="SalesPersonID" HeaderStyle-HorizontalAlign="Left"
HeaderText="Sales Person Name" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OrderDate" HeaderStyle-HorizontalAlign="Left"
HeaderText="Order Date" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="OrderValue" HeaderStyle-HorizontalAlign="Left"
HeaderText="Order Value" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="checkOrderList" runat="server" ValidationGroup="ValCheckOrder" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%--<asp:LinkButton ID="btnView" Text="View" runat="server" CommandName="ViewIndividualOrder" />--%>
<asp:Button ID="btnViewOrder" runat="server" Text="View" ValidationGroup="ValCheckOrder"
CommandName="ViewIndividualOrder" OnClick="btnViewOrder_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
<asp:GridView ID="gdvOrderDetail" runat="server"
AutoGenerateColumns="False" onrowdatabound="gdvOrderDetail_RowDataBound"
onselectedindexchanged="gdvOrderDetail_SelectedIndexChanged" AllowPaging="True"
Width="100%" onpageindexchanging="gdvOrderDetail_PageIndexChanging">
<Columns>
<asp:BoundField DataField="Sl" HeaderStyle-HorizontalAlign="Center"
HeaderText="SL #" ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ProductID" HeaderStyle-HorizontalAlign="Left"
HeaderText="Product ID" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ProductName" HeaderStyle-HorizontalAlign="Left"
HeaderText="Product Name" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="UnitID" HeaderStyle-HorizontalAlign="Left"
HeaderText="Unit" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="PacketSize" HeaderStyle-HorizontalAlign="Left"
HeaderText="Packet Size" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Sales Rate" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblSalesRate" runat="server" Text='<%# Eval("SalesRate") %>' Font-Size="Smaller" />
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField DataField="SalesRate" HeaderStyle-HorizontalAlign="Left"
HeaderText="Sales Rate" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>--%>
<asp:BoundField DataField="OrderQty" HeaderStyle-HorizontalAlign="Left"
HeaderText="Order Qty" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="MemoQty" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox ID="txtMemoQty" runat="server" Font-Bold="True" Width="100px" OnTextChanged="txtMemoQty_TextChanged"
AutoPostBack="true" Enabled="true" onkeypress="return onlyNumbers();"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorMemoQTY" ValidationGroup="ValCheckOrderDetail"
runat="server" ControlToValidate="txtMemoQty" ErrorMessage="*" Font-Size="X-Large"
ForeColor="Red"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Amount") %>' Font-Size="Smaller" />
</ItemTemplate>
</asp:TemplateField>
<%--<asp:BoundField DataField="Amount" HeaderStyle-HorizontalAlign="Left"
HeaderText="Amount" ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>--%>
<asp:TemplateField HeaderText="Select" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="checkOrderList" runat="server" ValidationGroup="ValCheckOrderDetail" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
C# code:
protected void gdv_SelectedIndexChanged(object sender, EventArgs e)
{
int indx = 0;
indx = gdv.SelectedIndex;
string salesorderno = "";
string sectionid = "";
string sectionname = "";
string outletid = "";
string outletname = "";
string salespersonname = "";
string orderdate = "";
string ordervalue = "";
string ordercheck = "";
for (int i = 0; i < 1; i++)
{
salesorderno = gdv.Rows[indx].Cells[1].Text.ToString();
sectionid = gdv.Rows[indx].Cells[2].Text.ToString();
sectionname = gdv.Rows[indx].Cells[3].Text.ToString();
outletid = gdv.Rows[indx].Cells[4].Text.ToString();
outletname = gdv.Rows[indx].Cells[5].Text.ToString();
salespersonname = gdv.Rows[indx].Cells[6].Text.ToString();
orderdate = gdv.Rows[indx].Cells[7].Text.ToString();
ordervalue = gdv.Rows[indx].Cells[8].Text.ToString();
ordercheck = gdv.Rows[indx].Cells[9].Text.ToString();
}
lblOrderNo.Text = salesorderno;
lblSectionName.Text = sectionname;
lblOutletName.Text = outletname;
lblOrderDate.Text = orderdate;
LoadOrderReportDetailGrid(salesorderno);
}
protected void gdvOrderDetail_SelectedIndexChanged(object sender, EventArgs e)
{
}
test is sufficient to know the origin of the event.
Exemple :
private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(dataGrid1.SelectedItem!=null)
MessageBox.Show("aaaaaaaaaaa");
}
private void dataGrid2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (dataGrid2.SelectedItem != null)
MessageBox.Show("BBBBBbbBBBB ");
}
Just open the event window for the gridviews then select one of them and on the event window double click on the "selected index changed" event. it will move you to the code section. if you are in true procedure than the event binding is true. if not you have to change the definition of your procedure.
Here is the simple process.
copy the codes inside the procedure and paste them to a safe place.
delete the procedures related the gridviews
check the event page for gridviews to ensure there is nothing in the "selected index changed" event.
double click the first gridviews "selected index changed" event. it will create a blank procedure. paste the related code here.
do the same for second.
and the other thing check the validation groups of the gridviews in the properties window. they should be different :)
NOT: forgive me that i cannot write the code directly. because i am not with my own computer. I hope it works.