I have Gridview having multiple rows with textboxes and dropdownlists... I want to insert data with values of textboxes and dropdownlist from multiple rows at a time with stored procedures. How it is possible.. pls help me,
<asp:gridview ID="Gridview1" runat="server" ShowFooter="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:TextBox ID="txtFirstName" runat="server" CssClass="textbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:TextBox ID="txtLastName" runat="server" CssClass="textbox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:TextBox ID="txtDate" runat="server" CssClass="textbox"></asp:TextBox>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlAgeRange" runat="server">
<asp:ListItem Value="-1">Age Range</asp:ListItem>
</asp:DropDownList>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlRelationship" runat="server">
<asp:ListItem Value="-1">Relationship</asp:ListItem>
</asp:DropDownList>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlGender" runat="server">
<asp:ListItem Value="-1">Gender</asp:ListItem>
</asp:DropDownList>
</ItemTemplate></asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:gridview>
private void userInsert()
{
if (MessageBox.Show("Do you want to add the new data ?", "Confirm ", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
try
{
foreach (GridViewRow dRow in userDataGridView.Rows)
{
cmd.CommandText = string.Format(
"insert into users(first_name,last_name,default_rate,default_location,spi_user_id,nickname) values('{0}','{1}',{2},{3},{4},'{5}')",
userDataGridView.CurrentRow.Cells[0].Value.ToString(),
userDataGridView.CurrentRow.Cells[1].Value.ToString(),
userDataGridView.CurrentRow.Cells[2].Value.ToString(),
locationID2ComboBox.SelectedValue,
userDataGridView.CurrentRow.Cells[4].Value.ToString(),
userDataGridView.CurrentRow.Cells[5].Value.ToString());
con.Open();
cmd.ExecuteNonQuery();
}
MessageBox.Show("Your data has been added successfully ", "Saved info", ageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
userSelect();
}
}
}
Related
I have a page with two gridview; one is inside the modal pop up (grdEmpName) and the other is in the page (gvUser). Now, when the user select search button the modal pop up extender will pop up and then search employees. When the user select someone, the selected data should display to the textbox in the another gridview (gvUser).
Everything is working up to selection in modal pop up extender gridview (grdEmpName)but when I select no data pass to the other gridview. (gvUser). I need to display the selected data in the textbox.
ASPX:
<asp:GridView ID="gvUser" runat="server" Width="1024px"
PageSize="10"
AutoGenerateColumns = "False"
AllowSorting="true"
AllowPaging="true"
ShowFooter="True"
OnSorting="gvUser_Sorting"
OnPageIndexChanging="gvUser_PageIndexChanging"
OnRowCreated="gvUser_RowCreated"
CssClass="Grid"
AlternatingRowStyle-CssClass="alt"
PagerStyle-CssClass="pgr"
FooterStyle-HorizontalAlign="center" >
<PagerSettings Mode="NumericFirstLast" PageButtonCount="5" FirstPageImageUrl="~/images/gridview/first_16x16.png" LastPageImageUrl="~/images/gridview/last_16x16.png" />
<Columns>
<asp:TemplateField>
<ItemTemplate >
<asp:ImageButton ID="ibtnEdit" runat="server" ImageUrl="~/images/gridview/file_edit_24x24.png" title = "Edit" _CommandArgument='<%# Eval("USR_ID") & "|Edit|" & CType(Container,GridViewRow).RowIndex & "|-" %>' />
<asp:ImageButton ID="ibtnUpdate" runat="server" ImageUrl="~/images/gridview/file_save_24x24.png" visible="false" title="Update" _CommandArgument='<%# Eval("USR_ID") & "|Update|" & CType(Container,GridViewRow).RowIndex & "|-" %>' />
<asp:ImageButton ID="ibtnCancel" runat="server" ImageUrl="~/images/gridview/file_cancel_24x24.png" Visible="false" title="Cancel" _CommandArgument='<%# Eval("USR_ID")& "|Cancel|" & CType(Container,GridViewRow).RowIndex & "|-" %>' />
<asp:ImageButton ID="ibtnDelete" runat="server" ImageUrl="~/images/gridview/file_delete_24x24.png" title="Delete" _CommandArgument='<%# Eval("USR_ID")& "|Delete|" & CType(Container,GridViewRow).RowIndex & "|" & Eval("USR_IDNTY") %>' />
<asp:ImageButton ID="btnSearchUser" runat="server" ImageUrl="~/images/gridview/file_search_24x24.png" title="Search" _CommandArgument= "btnSearchUser" OnClick = "btnSearchUser_Click" />
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="ibtnAdd" runat="server" ImageUrl="~/images/gridview/file_add_24x24.png" title="Add" _CommandArgument='<%# Eval("USR_ID") & "|Add|" & CType(Container,GridViewRow).RowIndex & "|-" %>' />
</FooterTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" Width="50px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="User Identity" visible ="false" >
<ItemTemplate>
<asp:Label ID="lblUSR_IDNTY" runat="server" Text='<%# Bind("USR_IDNTY")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblUSR_IDNTY" runat="server" Width="95%" Text='<%# Bind("USR_IDNTY")%>' />
</EditItemTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="User ID" SortExpression="USR_ID">
<ItemTemplate>
<asp:Label ID="lblUSR_ID" runat="server" Text='<%# Bind("USR_ID")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtUSR_ID" runat="server" Width="95%" Text='<%# Bind("USR_ID")%>' />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtUSR_ID" runat="server" Width="95%"/>
</FooterTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name" SortExpression="NAME">
<ItemTemplate>
<asp:Label ID="lblNAME" runat="server" Text='<%# Bind("NAME")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNAME" runat="server" Width="95%" Text='<%# Bind("NAME")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNAME" runat="server" Width="95%"/>
</FooterTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="EMAIL">
<ItemTemplate>
<asp:Label ID="lblEMAIL" runat="server" Text='<%# Bind("EMAIL")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEMAIL" runat="server" Width="95%" Text='<%# Bind("EMAIL")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEMAIL" runat="server" Width="95%"/>
</FooterTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Active" SortExpression="ACTIVE">
<ItemTemplate>
<asp:CheckBox ID="chkACTIVE" runat="server" Checked ='<%# Bind("ACTIVE")%>' Enabled="false" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkACTIVE" runat="server" Width="95%" Checked ='<%# Bind("ACTIVE")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="chkACTIVE" runat="server" Width="95%"/>
</FooterTemplate>
<HeaderStyle Wrap="False" />
<ItemStyle HorizontalAlign="Center" Wrap="False"/>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div style="height:315px;border-style:hidden;" >
<table class="table" >
<tr>
<td style="padding:5px;" >
<img id="Img1" style="height:24px;width:24px; " runat="server" src="images/no_data_64x64.png" />
</td>
<td style="padding:5px;font-size:large;">
<b>No data found.</b>
</td>
</tr>
</table>
</div>
</EmptyDataTemplate>
<PagerStyle CssClass="pgr" />
<AlternatingRowStyle CssClass="alt" />
<FooterStyle HorizontalAlign="Center" />
<EmptyDataRowStyle CssClass="EmptyData" />
</asp:GridView>
</div>
<%-- Picker--%>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:ModalPopupExtender runat="server" TargetControlID="hdControl" ID="mdlEmpListProcess" PopupControlID="empPanel" CancelControlID="btnClose" OnCancelScript="getFlickerSolved();" >
</cc1:ModalPopupExtender>
<asp:HiddenField runat="server" ID="hdControl" />
<asp:Panel runat="server" ID="empPanel" Width="909px" Height="300" BorderStyle="Ridge" BorderColor="Gray" Style="display:none;" BackColor="Control">
<table>
<tr>
<td>
<asp:TextBox runat="server" id="txtEmpName" CssClass="textbox" Width="240"></asp:TextBox>
<asp:Button runat="server" ID="btnSearchEmp" CssClass="button" Text="SEARCH" OnClientClick="getFlickerSolved();"/>
<asp:Button runat="server" ID="btnClose" CssClass="button" Text="CLOSE" />
</td>
</tr>
</table> <br />
<div style="overflow:scroll; width:882px; height:233px;">
<asp:GridView runat="server" ID="grdEmpName" Width="863px" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" Height="35px" GridLines="Vertical">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton runat="server" ID="optEmp" AutoPostBack="true" _CommandArgument= "Select" OnCheckedChanged="selectedEmployee" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="USR_ID" HeaderText="USER ID"/>
<asp:BoundField DataField="NAME" HeaderText="NAME"/>
<asp:BoundField DataField="EMAIL" HeaderText="EMAIL ADDRESS">
<HeaderStyle Width="300px" />
</asp:BoundField>
</Columns>
<RowStyle CssClass="rowStyle" />
<HeaderStyle CssClass="headerStyle" BackColor="Black" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
</div>
</asp:Panel>
<%-- End Picker--%>
Now, here's may code for selectedEmployee (Radio Button)
Protected Sub selectedEmployee(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lnBTNDone As RadioButton = DirectCast(sender, RadioButton)
Dim row As GridViewRow = DirectCast(lnBTNDone.NamingContainer, GridViewRow)
Dim RowIndex As Integer = gvUser.EditIndex
Dim dt As New DataTable
dt = TryCast(Session("dbCache_User"), DataView).Table.Copy
Dim dv As New DataView(dt, "", "USR_IDNTY", DataViewRowState.OriginalRows)
Dim s As String = TryCast(gvUser.Rows(RowIndex).FindControl("lblUSR_IDNTY"), Label).Text
Dim idx As Integer = dv.Find(s)
dv(idx)("USR_ID") = row.Cells(1).Text
dv(idx)("NAME") = row.Cells(2).Text
dv(idx)("EMAIL") = row.Cells(3).Text
gvUser.DataSource = dv
gvUser.DataBind()
Me.mdlEmpListProcess.Hide()
End Sub
But I've encounter this error when debugging system.data.dataexception was unhandled by user code. Cannot set Name when passing the value.
dv(idx)("NAME") = row.Cells(2).Text
as per you comment NAME is readonly field error given at runtime than you make is readonly false as below , add same line in your code after reading value
dt.Columns["NAME"].ReadOnly = false
Working example
DataTable dataTable = new DataTable("dataTable");
DataColumn dataColumn = new DataColumn("dataColumn");
dataTable.Columns.Add(dataColumn);
// Add ten rows.
DataRow dataRow;
for (int i = 0; i < 10; i++)
{
dataRow = dataTable.NewRow();
dataRow["dataColumn"] = "item " + i;
dataTable.Rows.Add(dataRow);
}
dataTable.AcceptChanges();///add this line in your code
var dv = new DataView(dataTable, "", "dataColumn", DataViewRowState.OriginalRows);
int index = dv.Find("item 1");
if (index == -1)
Console.WriteLine("Product not found");
else
dv[index]["dataColumn"] = "item 1000";
I suggest first check you are able to find row or not
int idx = dv.Find(s);
if (index == -1)
{
Console.WriteLine ("Product not found");
}
else
{
dv[index]["columnname"] = "value";
}
I have a gridview where the first column are check boxes, the next column is ID's. I have hidden labels on the page that need to get the current ID for any check boxes checked. The labels are specific, hlbl_pain1, hlbl_pain2, hlbl_pain3. It doenst matter which label gets which ID I just need each of the 3 hidden labels to be populated with ID's. Right now on CheckedChanged the 3 labels all update with the same value. I'm having issues looping. This is in VB.
Here's my grid:
<asp:GridView ID="gv_pain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="ds_grid_pain" ForeColor="Black" GridLines="Vertical" style="text-align: left; font-size: x-small; ">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxPain" runat="server" AutoPostBack="True" Checked="false" OnCheckedChanged="CheckBoxPain_CheckedChanged" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("DrugID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DrugID" InsertVisible="False" SortExpression="DrugID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DrugID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_DrugID" runat="server" Text='<%# Bind("DrugID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NickName" HeaderText="NickName" SortExpression="NickName" ItemStyle-Width="150px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DrugName" HeaderText="DrugName" SortExpression="DrugName" ItemStyle-Width="500px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan1" HeaderText="Quan1" SortExpression="Quan1">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan2" HeaderText="Quan2" SortExpression="Quan2">
<ItemStyle Wrap="False" />
</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>
Here are my labels:
<asp:Label ID="hlbl_pain1" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain2" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain3" runat="server" Visible="true"></asp:Label>
Here's what I'm trying to do in my CheckedChanged in the codebehind:
Protected Sub CheckBoxPain_CheckedChanged(sender As Object, e As System.EventArgs)
Dim row As GridViewRow
For Each row In gv_pain.Rows
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
If cbPain.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain1.Text = lblDrugID.text
End If
Dim cbPain1 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain1.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain2.Text = lblDrugID.text
End If
Dim cbPain2 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain2.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain3.Text = lblDrugID.text
End If
Next
End Sub
I have grid view
<cc1:GridView ID="gvMenu" runat="server" AllowPaging="False" AllowSorting="False"
AutoGenerateColumns="False" CssClass="mGrid" Width="100%" DataKeyNames="ID,MenuName"
DataSourceID="OdsGetMenuDetails" OnRowDataBound="gvMenu_RowDataBound">
<%--OnRowDataBound="gvAddLeave_RowDataBound"--%>
<AlternatingRowStyle CssClass="alt" />
<HeaderStyle CssClass="GridViewHeaderStyle" />
<PagerStyle CssClass="pgr" />
<RowStyle Wrap="false" />
<EmptyDataRowStyle BackColor="#edf5ff" Height="300px" HorizontalAlign="Center" VerticalAlign="Middle" />
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Sr.No">
<ItemTemplate>
<%# (gvMenu.PageIndex * gvMenu.PageSize) + Container.DataItemIndex + 1%>
</ItemTemplate>
<HeaderStyle CssClass="style4" ForeColor="White" Width="5%" />
<ItemStyle CssClass="style4" />
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="Menu ID" SortExpression="ID" Visible="false">
<HeaderStyle CssClass="style4" Width="100px" HorizontalAlign="Left" ForeColor="White" />
<ItemStyle CssClass="style4" />
</asp:BoundField>
<asp:BoundField DataField="MenuName" HeaderText="MenuName" SortExpression="MenuName">
<HeaderStyle CssClass="style4" Width="80%" HorizontalAlign="Left" ForeColor="White" />
<ItemStyle CssClass="style4" />
</asp:BoundField>
<asp:TemplateField HeaderText="View">
<HeaderTemplate>
<asp:CheckBox ID="chkHeaderApprove" runat="server" Text="View" onclick="javascript:SelectAllCheckboxes1(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</cc1:GridView>
with this objectDataSource
<asp:ObjectDataSource ID="OdsGetMenuDetails" runat="server" SelectMethod="GetMenuName"
EnablePaging="true" TypeName="AdsWorksDBMenuAuthorizationDAL" StartRowIndexParameterName="startIndex"
SortParameterName="sortBy" MaximumRowsParameterName="pageSize" SelectCountMethod="GetMenuCount">
</asp:ObjectDataSource>
I want to do the <asp:CheckBox ID="chkHeaderApprove" > checked when all my <asp:CheckBox ID="chkApprove"> is checked??
I am not able to do this please help me some more....
Add this:
<asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' OnCheckedChanged="chkApprove_CheckChanged"/>
And in code behind:
protected void chkApprove_CheckChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
GridView g1 = (GridView)cb.Parent.Parent;
foreach (GridViewRow item in g1.Rows)
{
CheckBox currentCheckBox = (CheckBox)item.FindControl("chkApprove");
if (currentCheckBox.Checked != true)
return;
}
CheckBox chkHeaderApprove = (CheckBox)g1.FindControl("chkHeaderApprove");
chkHeaderApprove.Checked = true;
}
This should work.. didn't check. Anyways client side should be better, go for that.. This is just a easy server side solution.
I have a search page. In list the search results are displayed.
When I select another page from page numbers, the search result is disappeared and show the list like the page is refreshed. What should I do? I tried OnSelectedIndexChanged and OnSelectedIndexChanging. And didn't work. Thank you.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="ahsun" ForeColor="#333333" GridLines="None" Width="100%"
DataKeyNames="SICIL_NO" OnSelectedIndexChanged="LinkButton1_Click" CssClass="icerik" o >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
CssClass="hover" Text="Seç"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adı" SortExpression="ADI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" Text='<%# Bind("ADI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Soyadı" SortExpression="SOYADI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton4" runat="server" Text='<%# Bind("SOYADI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birimi" SortExpression="BIRIMI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" Text='<%# Bind("BIRIMI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Görevi" SortExpression="GOREVI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton6" runat="server" Text='<%# Bind("GOREVI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="ahsun" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>"
ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
SelectCommand="select SICIL_NO, ADI, SOYADI, BIRIMI ,GOREVI,PERSON_ID from xxah_hr_calisanlar WHERE SICIL_NO <> '01470' "></asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4" DataKeyNames="SICIL_NO"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px"
Width="100%" CaptionAlign="Left" AutoGenerateRows="False" CssClass="icerik">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" Width="75%" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="25%" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"
Width="25%" />
<AlternatingRowStyle BackColor="White" />
<Fields>
<asp:BoundField DataField="ADI" HeaderText="Adı" SortExpression="ADI" />
<asp:BoundField DataField="SOYADI" HeaderText="Soyadı" SortExpression="SOYADI" />
<asp:BoundField DataField="BIRIMI" HeaderText="Birimi" SortExpression="BIRIMI" />
<asp:BoundField DataField="GOREVI" HeaderText="Görevi" SortExpression="GOREVI" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>" EnableCaching="True"
ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
SelectCommand="select c.* from TABLE c where c.SICIL_NO=:sicil" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="sicil" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
For pagination You need to work on PageIndexChanging.Nothing to do with OnSelectedIndexChanged.
For Example:
Method
protected void BindData()
{
string strConnection = "Data Source=.; uid=sa; pwd=wintellect;database=Rohatash;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Userinfo", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
PageIndexChanging
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindData();
}
Try enabling ViewState on the datasource in your aspx page by adding EnableViewState="true" and ViewStateMode="Enabled"
I can't get the value. What I do get is a blank value or videoName = " ". How can I get the value of videoName? In the rowdeleting event, I am using Rows(e.Index).Cells(2).Text to get the value but it is blank. Is there another way to get the field, "videoname"?
Protected Sub GridView1_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
Dim videoName As String = gridview1.Rows(e.RowIndex).Cells(2).Text
Dim val As String = videoName
If File.Exists(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName) Then
File.Delete(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName)
End If
End Sub
<asp:GridView id="GridView1" runat="server" Width="680px" GridLines="None" DataSourceID="SqlDataSource2" DataKeyNames="id" CellSpacing="1" CellPadding="3" BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" EmptyDataText="No Record Found" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="9" >
<Columns>
<asp:BoundField HeaderText="Id" DataField="Id" ReadOnly="true" visible="false" />
<asp:BoundField HeaderText="CustomerID" DataField="CustomerID" ReadOnly="true" visible="false"/>
<asp:BoundField HeaderText="VideoName" DataField="VideoName" ReadOnly="true" visible="false"/>
<asp:TemplateField>
<HeaderStyle Width="5%" />
<ItemStyle Width="5%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this video?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Clip" SortExpression="ThumbName">
<HeaderStyle Width="5%" />
<ItemStyle Width="5%" />
<ItemTemplate>
<div style="margin:2px; width:133px; background-color:rgb(68,68,68); -moz-box-shadow: 5px 5px 5px rgba(68,68,68,0.6); -webkit-box-shadow:5px 5px 5px rgba(68,68,68,0.6);box-shadow:5px 5px 5px rgba(68,68,68,0.6); zoom: 1;">
<asp:hyperlink id="link" NavigateUrl='<%# Eval("VideoName", "~/Test/playVideos2.aspx?FileName={0}&Thumb=" + Eval("ThumbName") + "&Duration=" + Eval("Duration"))%>' runat="server">
<asp:image id="img" ImageUrl='<%# String.Format("~/contents/thumbs/{0}",Eval("ThumbName"))%>' width="130" height="80" runat="server" />
</asp:hyperlink>
<asp:Label ID="lblMovieName" Text='<%#Bind("VideoName") %>' runat="server"></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<HeaderStyle Width="15%" />
<ItemStyle Width="15%" />
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Bind("DateCreated") %>'></asp:Label><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle Width="75%" />
<ItemStyle Width="75%" />
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
This is prone to erros when you add or delete a column from gridview in future your code would fail again. I suggest you use a label inside template field for your MovieName field & use FindControl to find your label.
Aspx
<asp:TemplateField HeaderText="Movie Name" >
<ItemTemplate>
<asp:Label ID="lblMovieName" Text='<%#Bind("MovieName") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Code behind
protected void gvCustomer_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lblMovieName = gvCustomer.Rows[e.RowIndex].FindControl("yourLableControlName") as Label;
// Perform your delete
}
Updated
I found that in your code you have the movieName Visibleproperty set to false. This will prevent it from rendering on page. You can either store values in DataKeys or remove visible=false to fetch desired value.