I'm having a wired problem with Radgrid.. Im using a Radgrid to display some results where the user can edit/update/delete them. I'm using a single SQL Server 2000 table to fetch the results... Not sure why the events are not firing in radgrid. But I am able to do it successfully using the Gridview control...
Im using .NET framework 4
Radgrid code
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True" DataSourceID="SSDS" GridLines="None" Width="844px"
DataMember="DefaultView">
<MasterTableView DataSourceID="SSDS" DataKeyNames="id">
<Columns>
<telerik:GridBoundColumn DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id"
UniqueName="id" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="name" HeaderText="name" SortExpression="name"
UniqueName="name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="address" HeaderText="address" SortExpression="address"
UniqueName="address">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<br />
<br />
<asp:SqlDataSource ID="SSDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringSQL %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringSQL.ProviderName %>" SelectCommand="SELECT [id], [name], [address] FROM [sitelinks]"
UpdateCommand="UPDATE [sitelinks] set [name] = ? , [address] = ? where [id] = ?"
DeleteCommand="delete from sitelinks where id = ?">
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="name" />
<asp:Parameter Name="address" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
Gridview control code (the one that works)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SSDS"
DataKeyNames="id">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" Visible="false" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SSDS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringSQL %>"
DeleteCommand="delete from sitelinks where id = ?" ProviderName="<%$ ConnectionStrings:ConnectionStringSQL.ProviderName %>"
SelectCommand="select id,name,address from sitelinks" UpdateCommand="update sitelinks set name=?, address=? where id = ? ">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="name" />
<asp:ControlParameter ControlID="GridView1" Name="address" />
<asp:ControlParameter ControlID="GridView1" Name="id" />
</UpdateParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="id" />
</DeleteParameters>
</asp:SqlDataSource>
Thanks
Set the AllowAutomaticUpdates/AllowAutomaticDeletes properties of the telerik grid to true and see this sample.
Related
I use griview propertied while editing or deleting records without coding
When I click on edit button my image is also converted into a TextBox control,
I want to take
Fileupload control instead of textBox control.
For it which property shoule i set?
my code is as follow
<asp:GridView ID="GridView1" runat="server" Width="197px"
AutoGenerateColumns="False" DataKeyNames="ProductID"
DataSourceID="SqlDataSource2" AllowPaging="True">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />
<asp:ImageField DataImageUrlField="Image" HeaderText="PHOTO">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="status" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
And here is the code of SqlDataSource2:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStringnewdb %>"
DeleteCommand="delete from Product where ProductID=#ProductID"
SelectCommand="SELECT * FROM [Product]"
UpdateCommand="update Product set ProductName=#ProductName,Status=#Status where ProductID=#ProductID ">
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductID"
PropertyName="SelectedValue" />
</DeleteParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductName"
PropertyName="SelectedValue" />
<asp:Parameter Name="ProductID" />
</UpdateParameters>
</asp:SqlDataSource>
Use the EditItemTemplate and add the FileUpload control:
... other columns ...
</EditItemTemplate>
<ItemTemplate>
<asp:FileUpload id="FileUpload1" runat="server">
</asp:FileUpload>
</ItemTemplate>
</asp:TemplateField>
... other columns ...
Here's a tutorial: http://msdn.microsoft.com/en-us/library/ms972948.aspx
I have a problem about the updating a column of my gridview; when I try to update the field I get this error:
Incorrect syntax near 'nvarchar'.
Must declare the scalar variable "#pid".
Here is a piece of my code:
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe rozane" HeaderText="hoghoghe rozane"
SortExpression="hoghoghe rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
<asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
chek this out : same problem
it says you must change [hoghoghe rozane] into [hoghoghe_rozane]
Update :::
1.Make sure that the type of pid field in database
2.fields should not have spaces in your tables
3.alias should not have spaces too
try this code :
<asp:GridView ID="GridView1" runat="server" name="gd" Height="100px"
Width="435px" AutoGenerateColumns="False" DataKeyNames="pid" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="pid" HeaderText="pid"
SortExpression="pid" ReadOnly="True" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="hoghoghe_rozane" HeaderText="hoghogheRozane"
SortExpression="hoghoghe_rozane" />
<asp:BoundField DataField="paye" HeaderText="paye"
SortExpression="paye" />
<\Columns>
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
UpdateCommand="UPDATE [post] SET [name] = #name, hoghoghe_rozane = #hoghoghe_rozane, [paye] = #paye WHERE (pid = #pid)" >
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="hoghoghe_rozane" Type="Int32" />
<asp:Parameter Name="paye" Type="Int32" />
<asp:Parameter Name="pid" Type="String" />
</UpdateParameters>
hope that would work.
My DetailsView is always blank. I've tested both Data Sources in QueryBuilder and they return values. I suspect something is wrong with the parameter value assignments in PoweredEquipDetails where they are set to the SelectedValue in GridView1, but I don't know why it wouldn't work.
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="PoweredEquipHeader" DataKeyNames="Model,Serial">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Model" HeaderText="Model" ReadOnly="True"
SortExpression="Model" />
<asp:BoundField DataField="Serial" HeaderText="Serial" ReadOnly="True"
SortExpression="Serial" />
</Columns>
<SelectedRowStyle BackColor="#FF6600" />
</asp:GridView>
<asp:SqlDataSource ID="PoweredEquipHeader" runat="server"
ConnectionString="<%$ ConnectionStrings:CPECConnectionString %>"
SelectCommand="Select t1.Model, t1.Serial From Powered_Equip t1 Where TechID = #TechID And Store = #Store">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="TECH01" Name="TechID"
QueryStringField="Tech" />
<asp:QueryStringParameter DefaultValue="0000" Name="Store"
QueryStringField="Store" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="PoweredEquipDetail" runat="server"
ConnectionString="<%$ ConnectionStrings:CPECConnectionString %>"
SelectCommand="SELECT t1.Serial, t1.Model, t1.Status, t1.[Trailer VIN], t2.Tag, t2.State, t2.ExpMonth, t2.ExpYear FROM Powered_Equip AS t1 INNER JOIN Trailers AS t2 ON t1.[Trailer VIN] = t2.VIN WHERE (t1.Serial = #Serial) AND (t1.Model = #Model)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Serial"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1" Name="Model"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="PoweredEquipDetail" DataKeyNames="Serial,Model">
<Fields>
<asp:BoundField DataField="Serial" HeaderText="Serial" ReadOnly="True"
SortExpression="Serial" />
<asp:BoundField DataField="Model" HeaderText="Model"
ReadOnly="True" SortExpression="Model" />
<asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True"
SortExpression="Status" />
<asp:BoundField DataField="Trailer VIN" HeaderText="Trailer VIN" ReadOnly="True"
SortExpression="Trailer VIN" />
<asp:BoundField DataField="Tag" HeaderText="Tag" ReadOnly="True"
SortExpression="Tag" />
<asp:BoundField DataField="State" HeaderText="State" ReadOnly="True"
SortExpression="State" />
<asp:BoundField DataField="ExpMonth" HeaderText="ExpMonth" ReadOnly="True"
SortExpression="ExpMonth" />
<asp:BoundField DataField="ExpYear" HeaderText="ExpYear" ReadOnly="True"
SortExpression="ExpYear" />
</Fields>
</asp:DetailsView>
</form>
EDIT: So I believe what is happening is the GridView's SelectedValue in the DetailsView parameter assignments is always Model, instead of both Model and Serial as specified in my DataValueKeys. In the event that an equipment item has a model and serial that are the same value (i.e. Model 118 Serial 118), the DetailsView populates. But in any case where the Model and Serial are different (which will be almost every other case), the DetailsView is blank. So how do I get two different SelectedValues to assign value to two different ControlParameters?
Changed
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Serial"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1" Name="Model"
PropertyName="SelectedValue" />
</SelectParameters>
to
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Serial"
PropertyName="SelectedDataKey.Values[Serial]" />
<asp:ControlParameter ControlID="GridView1" Name="Model"
PropertyName="SelectedValue" />
</SelectParameters>
int n = int.Parse(GridView1.SelectedValue.ToString());
TextBox4.Text = n.ToString();
con = new SqlConnection(#"Data Source=LAB-III-136;Initial Catalog=student;Integrated Security=True");
con.Open();
da = new SqlDataAdapter("select * from student1 where id='" + TextBox4.Text + " '", con);
ds = new DataSet();
da.Fill(ds, "temp");
DetailsView2.DataSource = ds;
DetailsView2.DataBind();
Please forgive my ignorance. I have a done a bit of web programming but am new to ASP.NET and find it mystifying when trying to do something not out of the box.
I have a GridView that gets its data from a SQL Server view. I have a DetailsView that needs to manipulate data in a table. I cannot figure out how to link the GridView to the DetailsView correctly.
Below is the code for the section of the aspx page that contains the GridView and DetailsView. The latest error in an endless procession of errors is: Must declare the scalar variable "#ID".
I would appreciate any help that anyone can offer. Thanks.
<asp:GridView ID="gvVendorContacts" runat="server" AutoGenerateColumns="False"
DataSourceID="dsApplications_Contacts" AllowSorting="True" CellPadding="4" CellSpacing="2" AutoGenerateSelectButton="True" DataKeyNames="ContactID"
onselectedindexchanged="gvVendorContacts_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#E8F3FF" />
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Name" ReadOnly="True"
SortExpression="FullName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="Office Phone" HeaderText="Office Phone"
SortExpression="Office Phone" />
<asp:BoundField DataField="Mobile Phone" HeaderText="Mobile Phone"
SortExpression="Mobile Phone" />
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<%#Eval("Email")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsApplications_Contacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
SelectCommand="SELECT [ApplicationID], [ContactID], [FName], [LName], [FullName], [Title], [Role], [OfficePhone] As [Office Phone], [MobilePhone] As [Mobile Phone], [Email] FROM [vw_Applications_Contacts] WHERE ApplicationName = 'Bloomberg'">
</asp:SqlDataSource>
<asp:DetailsView ID="dvVendorContacts" runat="server" AutoGenerateRows="False"
DataKeyNames="ID" DataSourceID="dsVendorContacts" Height="100px"
Width="200px" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4">
<EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<Fields>
<asp:BoundField DataField="ContactID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" />
<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" />
<asp:BoundField DataField="OfficePhone" HeaderText="OfficePhone"
SortExpression="OfficePhone" />
<asp:BoundField DataField="MobilePhone" HeaderText="MobilePhone"
SortExpression="MobilePhone" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
</Fields>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
</asp:DetailsView>
<asp:SqlDataSource ID="dsVendorContacts" runat="server"
ConnectionString="<%$ ConnectionStrings:MDSConnectionString %>"
DeleteCommand="DELETE FROM [Contacts] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Contacts] ([FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email]) VALUES (#FName, #LName, #Title, #Role, #OfficePhone, #MobilePhone, #Email)"
SelectCommand="SELECT [ID], [FName], [LName], [Title], [Role], [OfficePhone], [MobilePhone], [Email] FROM [Contacts] WHERE ([ID] = #ID)"
UpdateCommand="UPDATE [Contacts] SET [FName] = #FName, [LName] = #LName, [Title] = #Title, [Role] = #Role, [OfficePhone] = #OfficePhone, [MobilePhone] = #MobilePhone, [Email] = #Email WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FName" Type="String" />
<asp:Parameter Name="LName" Type="String" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Role" Type="String" />
<asp:Parameter Name="OfficePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvVendorContacts" DefaultValue="NULL"
Name="ContactID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Looks like your select statement is expecting #ID but your SelectParameter is ContactId.
I have grid view with folowing complete code With Msaccess DB.I have used the decode function in sql query.When i press the edit button on grid view it shows folowing error
"DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
My SQL Data source code is below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString2 %>"
DeleteCommand="DELETE FROM [EMAILS] WHERE [ID] = ?" InsertCommand="INSERT INTO [EMAILS] ([Email], [FULLNAME],[FLAG]) VALUES (?, ?, ?)"
ProviderName="<%$ ConnectionStrings:DataConnectionString2.ProviderName %>" SelectCommand="SELECT ID, Email, FULLNAME, switch(FLAG = 1, 'Allowed', Flag = 0, 'Not Allowed') AS FLAG FROM EMAILS"
UpdateCommand="UPDATE [EMAILS] SET [Email] = ?, [FULLNAME] = ?,[FLAG] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
And Grid View Code is bellow
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="821px" EmptyDataText="No Emails Found">
<RowStyle BackColor="White" Font-Names="Arial" Font-Size="Small" ForeColor="Black" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="FULLNAME" HeaderText="Full Name" SortExpression="FULLNAME" />
<asp:TemplateField HeaderText="Flag" SortExpression="FLAG">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue="<%# Bind('FLAG') %>" AppendDataBoundItems="True">
<asp:ListItem Value="1">Allowed</asp:ListItem>
<asp:ListItem Value="0">Not Allowed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FLAG") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
ForeColor="#FFFFCC" HorizontalAlign="Center" />
<EmptyDataRowStyle BackColor="#804000" Font-Names="Arial" Font-Size="Small" ForeColor="White" />
</asp:GridView>
Please tell me what possible error is here
Check weather the value in Field flag of the row you are trying to edit, is available in the DropDownList in EditItemTemplate
And try removing AppendDataBoundItems="True" in DropDownList in EditItemTemplate