Aspx Code:
<asp:GridView ID="PaperReviewing" runat="server" CellPadding="4" EmptyDataText="There is no Submission"DataKeyNames="PaperId" RowStyle-Wrap="true" OnRowDataBound="PaperReviewing_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Action" ControlStyle-Width="200px" >
<ItemTemplate>
<br />
<asp:HyperLink ID="HyperLink3" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
NavigateUrl='<%# String.Format("~/EditorsInChief/DownloadSubFileList.aspx?ID={0}", Eval("PaperId")) %>' runat="server">File Inventory</asp:HyperLink>
<br /><asp:HyperLink ID="HyperLink4" Target="_blank" ForeColor="Black" onclick="javascript:window.open(this.href,'ManuScript Details','resizable=no,scroll bars=yes,status=no,toolbar=yes,height=500,width=700,left=50,top=40');return true;"
NavigateUrl='<%# String.Format("~/EditorsInChief/SelectReviewer.aspx?ID={0}", Eval("PaperId")) %>' runat="server">Select Another Reviewer</asp:HyperLink>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PaperId" HeaderText="PaperId" InsertVisible="False"
ReadOnly="True" SortExpression="PaperId" Visible="False" />
<asp:BoundField DataField="ManuScriptId" HeaderText="ManuScript Number"
SortExpression="ManuScriptId" />
<asp:BoundField DataField="Type" HeaderText="Article Type" SortExpression="Type" />
<asp:TemplateField HeaderText="Article Title" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" SortExpression="PaperTitle" ControlStyle-Width="200px">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("PaperTitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ReviewerName" HeaderText="Reviewer Name" SortExpression="ReviewerName" />
<asp:BoundField DataField="Status" HeaderText="Current Status"
SortExpression="Status" />
<asp:BoundField DataField="CreatedDate" HeaderText="Intital Date Submission" SortExpression="CreatedDate" />
<asp:BoundField DataField="DateReviewInvited" HeaderText="Date Review Invited"
SortExpression="DateReviewInvited" />
<asp:BoundField DataField="DateReviewDue" HeaderText="Date Review Due"
SortExpression="DateReviewDue" />
<asp:TemplateField HeaderText="EIC Decision">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True" Text="Choose Option"></asp:ListItem>
<asp:ListItem Text="Accept" Value="Accept"></asp:ListItem>
<asp:ListItem Text="Reject" Value="Reject"></asp:ListItem>
<asp:ListItem Text="Minor Revision" Value="MinorRevision"></asp:ListItem>
<asp:ListItem Text="Major Revision" Value="MajorRevision"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" BorderStyle="Double" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
C# Code :
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DropDownList1 = (DropDownList)sender;
GridViewRow grdrDropDownRow = ((GridViewRow)DropDownList1.Parent.Parent);
}
protected void PaperReviewing_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("DropDownList1") as DropDownList;
if (ddl != null)
{
ddl.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
}
}
}
the drop down selectedindexchanged event does not fire. I am trying to do as my drop down value changes at run time , in my database value get updates.
remove the event handler adding code from PaperReviewing_RowDataBound since you are already attached it from the markup
in your page load
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
DataBindGrid();
}
}
Related
I am fairly new to Asp.Net. I have been trying to Edit a column value in a gridview but upon checking one of the two checkboxes (Yes or No), it does not update anything.
Sharing Gridview code below :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#000000" BorderStyle="Solid"
BorderWidth="2px" CellPadding="6" DataKeyNames="film_data" DataSourceID="SqlDataSource" ForeColor="White"
GridLines="Vertical" onrowdatabound="GridView1_RowDataBound" AllowSorting="True">
<AlternatingRowStyle BackColor="#CCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True">
<ControlStyle ForeColor="Blue" />
</asp:CommandField>
<asp:BoundField DataField="film_title" HeaderText="MOVIE TITLE" ReadOnly="True" SortExpression="film_title" >
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="film_release" HeaderText="RELEASE DATE" ReadOnly="True" SortExpression="release_date" >
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:CheckboxField DataField="Yes" HeaderText="YES" SortExpression="Yes" />
<asp:CheckboxField DataField="No" HeaderText="NO" SortExpression="No" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle />
</asp:GridView>
This is the GridView1_RowDataBound snippet from .cs file.
public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Checking the RowType of the Row
if (e.Row.RowType == DataControlRowType.DataRow)
{
....
What am I missing here ? Upon clicking Edit, and the Yes or No checkboxes. nothing gets updated. There is no error either. Kindly assist.
In Gridview change the commandfield and checkbox control like this in your code
<asp:TemplateField HeaderText="Yes/No">
<ItemTemplate>
<asp:Literal ID="ltrchkboxVal" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "chkboxval").ToString() %>'></asp:Literal>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="hdnchkboxval" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "chkboxval").ToString() %>'/>
<asp:CheckboxList ID="chkyesboxval" runat="server" Width="40">
<asp:ListItem> Yes</asp:ListItem>
<asp:ListItem> No</asp:ListItem>
</asp:CheckboxList >
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" CancelText="Cancel" ControlStyle-CssClass="small"
EditText="Optimise" HeaderText="Optimise" ShowEditButton="true" UpdateText="Apply" ItemStyle-Width="30px">
</asp:CommandField>
IN c# code
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
DivMessage.Visible = false;
GridView1.EditIndex = e.NewEditIndex;
//Bind gridview
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string yesnoval = (GridView1.Rows[e.RowIndex].FindControl("chkyesboxval") as CheckBoxList).SelectedItem.Value;
// update new values and Bind gridview
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
//Bind gridview
}
Add events for the gridview control
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
How to get the row index of a dynamically created asp.net GridView so that I can edit the record in a text box outside the GridView.
This is the GridView:
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="RefID">
<ItemTemplate>
<asp:Label ID="lbl_Refid" runat="server" Text='<%# Eval("Refid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="lbl_date" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name Of Company">
<ItemTemplate>
<asp:Label ID="lbl_noc" runat="server" Text='<%# Eval("Name_Of_Company") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact/Email">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Contact") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:Label ID="lbl_wht_do" runat="server" Text='<%# Eval("Remarks") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btn_edit" runat="server" `enter code here` Text="Button" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand = "OnRowCommand">
Use
OnRowCommand = "OnRowCommand"
Now when any action happen on the grid the OnRowCommand event is executed.
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
}
More Info
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="MyButtonClick" />
</ItemTemplate>
and your method
protected void MyButtonClick(object sender, System.EventArgs e)
{
//Get the button that raised the event
Button btn = (Button)sender;
//Get the row that contains this button
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
}
everyone. I needed your help. I am creating an online workshop registration system. I have a inicale gridview that show the all the available workshop for registration during the festival time. I am using a session and check box to get the workshop that the person want into the "shopping cart" on the next page. what I needed to do is after righting a incial order written to an order table in my SQL database. What I am having issues with is when it write the registration data that is stored in an other gridview for the shopping cart. I am writing each row as a new entry into a order detail table. when I do this the program does something very odd. It seem to write all the data from the a gridview that holds all the workshop information on the first page.
code for writing the shopping cart row to the order detail table:
protected void btn_Submit_Click1(object sender, EventArgs e)
{
foreach (GridViewRow row in Basket.Rows)
{
Label lblCatCode = (Label)row.FindControl("lblCatCode");
Label lblTitle = (Label)row.FindControl("lblTitle");
SqlConnection conBasket = new SqlConnection("Data Source=JONS\\SQLEXPRESS;Initial Catalog=OFFFV2;Integrated Security=True");
SqlCommand cmdBasket = new SqlCommand("Insert into OrderDetail(OrderID,CatalogeCode,Title)Values(#OrderID,#CatCode,#Title)", conBasket);
cmdBasket.Parameters.AddWithValue("#OrderID", lblOrderNumber.Text);
cmdBasket.Parameters.AddWithValue("#CatCode", lblCatCode.Text);
cmdBasket.Parameters.AddWithValue("#Title", lblTitle.Text);
try
{
conBasket.Open();
cmdBasket.ExecuteNonQuery();
conBasket.Close();
}
catch (Exception ex)
{
lbl_Error.Text = "A database error has orrued. <br <br />" + "Message: " + ex.Message;
}
}
}
Here is the code for the gridview
<asp:GridView ID="Basket" runat="server" AutoGenerateColumns="False" DataKeyNames="WorkshopID" DataSourceID="BasketData" EnableViewState="False" ShowFooter="True" OnRowCreated="Basket_RowCreate" CellPadding="4" ForeColor="#333333" GridLines="None" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Remove">
<ItemTemplate>
<asp:CheckBox ID="cb_BasketRemove" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cataloge Code" SortExpression="CatalogeCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("CatalogeCode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCatCode" runat="server" Text='<%# Eval("CatalogeCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<strong>
Total Price:
</strong>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price" SortExpression="Price">
<ItemTemplate>
<asp:Label ID="Price" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<strong>
<asp:Literal ID="TotalPrice" runat ="server" />
</strong>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
I understand that my last post was unclear and was closed. I am at a loss as why the program is doing what it is doing. I am wondering if it is in connection with the way I get the data from the first gridview to the shopping cart.
Here is the code for the session for the selected row
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btt_Select_Click(object sender, EventArgs e)
{
var selectedWorkshop = GridView1.Rows.Cast<GridViewRow>().Where(row => ((CheckBox)row.FindControl("RegisteredWorkshop")).Checked).Select(row => GridView1.DataKeys[row.RowIndex].Value.ToString()).ToList();
if (Session["cart"] == null)
{
Session["cart"] = selectedWorkshop;
}
else
{
var cart = (List<string>)Session["cart"];
foreach (var workshop in selectedWorkshop)
cart.Add(workshop);
Session["cart"] = cart;
}
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("RegisteredWorkshop");
if (cb.Checked)
cb.Checked = false;
}
}
protected void btt_CheckOut_Click(object sender, EventArgs e)
{
if (Session["cart"] != null)
Response.Redirect("Checkout.aspx");
}
}
The code for the select gridview from where the registrant select from the various workshops:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" CellPadding="4" DataKeyNames="WorkshopID" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText ="Register">
<ItemTemplate>
<asp:CheckBox ID="RegisteredWorkshop" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FestivalYear" HeaderText="Festival Year" />
<asp:BoundField DataField="CatalogeCode" HeaderText="Catalog Code" />
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="WSDescription" HeaderText="Workshop Description" />
<asp:BoundField DataField="DayOffered" HeaderText="Day Offered" />
<asp:BoundField DataField="Lenght" HeaderText="Workshop Lenght" />
<asp:BoundField DataField="BeginingTime" HeaderText="Start Time" />
<asp:BoundField DataField="Price" HeaderText="Workshop Fee" />
<asp:BoundField DataField="WorkshopID" HeaderText="Workshop Id" Visible="False" />
</Columns>
I may be wrong but it looks like your variable naming is off (confusing basket and cart?).
You might need to do something like this:
protected void btn_Submit_Click1(object sender, EventArgs e)
{
var Basket = (List<string>)Session["cart"]; // ADD THIS LINE
foreach (GridViewRow row in Basket.Rows)
{
recently I asked a similar question, which you can find in the link below
Using Dropdownlist in a gridview Asp.Net?
I have a gridview that looks like this...
<asp:GridView ID="grdvEventosVendedor" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DatakeyNames="idCita"
EmptyDataText="No Hay Eventos Para Este Vendedor" ForeColor="#333333"
GridLines="None" AllowSorting="True"
onpageindexchanging="grdvEventosVendedor_PageIndexChanging"
onrowcommand="grdvEventosVendedor_RowCommand"
onsorting="grdvEventosVendedor_Sorting" CellSpacing="1"
onrowdatabound="grdvEventosVendedor_RowDataBound" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775"/>
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnEdicEvento" runat="server"
CommandArgument='<%# Eval("idCita")%>' CommandName="Edicion"
Height="32px" ImageUrl="~/img/pencil_32.png" Width="32px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" ItemStyle-Width="35px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnDelete" runat="server"
CommandName="Borrar"
ImageUrl="~/img/1385_Disable_16x16_72.png"
onclientclick="return confirm('¿Desea eliminar el registro?');"
CommandArgument='<%# Eval("idCita")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cliente" HeaderText="Cliente" InsertVisible="False" ReadOnly="True" SortExpression="Cliente" ItemStyle-Width="50px" />
<asp:BoundField DataField="Empresa" HeaderText="Empresa" InsertVisible="False" ReadOnly="True" SortExpression="Empresa" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Telefono" HeaderText="Telefono" InsertVisible="False" ReadOnly="True" SortExpression="Telefono" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Nextel" HeaderText="Nextel" InsertVisible="False" ReadOnly="True" SortExpression="Nextel" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Tipo" HeaderText="Tipo" InsertVisible="False" ReadOnly="True" SortExpression="Tipo" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Descripcion" HeaderText="Descripcion" InsertVisible="False" ReadOnly="True" SortExpression="Descripcion" ItemStyle-Width="100px"/>
<asp:TemplateField HeaderText="Fecha" SortExpression="Fecha" ItemStyle-Width="50px">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Fecha", "{0:dd/MM/yyyy}")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbxFecha" runat="server" Text='<%#Bind("Fecha","{0:dd/MM/yyyy}") %>' ValidationGroup="gpEdicionAgenda">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="HoraInicio" HeaderText="Hora" InsertVisible="False" ReadOnly="True" SortExpression="HoraInicio" ItemStyle-Width="50px"/>
<asp:BoundField DataField="Lugar" HeaderText="Lugar" InsertVisible="False" ReadOnly="True" SortExpression="Lugar" ItemStyle-Width="50px"/>
<%--<asp:BoundField DataField="Estado" HeaderText="Estado" InsertVisible="False" ReadOnly="True" SortExpression="Estado" ItemStyle-Width="50px"/>--%>
<asp:TemplateField HeaderText="Estado" ItemStyle-Width="50px">
<ItemTemplate>
<asp:DropDownList ID="dpdListEstado" runat="server" OnSelectedIndexChanged="dpdListEstado_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>Pendiente</asp:ListItem>
<asp:ListItem>Atendido</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CRM" ItemStyle-Width="25px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnCRM" runat="server"
CommandArgument='<%# Eval("IdCliente")%>' CommandName="CRM"
ImageUrl="~/img/activar.png" Width="16px" Height="16px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VM" ItemStyle-Width="25px">
<ItemTemplate>
<asp:ImageButton ID="imgBtnVerMas" runat="server"
CommandArgument='<%# Eval("IdCliente")%>' CommandName="VerMas"
ImageUrl="~/img/search.png" Width="16px" Height="16px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" Font-Size="Small" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Larger" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" Font-Size="Small" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
As mentioned in the link, I had to manually add some code, like OnSelectedIndexChanged="dpdListEstado_SelectedIndexChanged" AutoPostBack="True" and also add this on the cs file...
protected void dpdListEstado_SelectedIndexChanged(object sender, EventArgs e)
{
}
I have tried it and it did work, whenever I change the value of a ddl, it does enter to the void int the cs file...
however now I have a question...
I need the Id from the record that it's stored in a specific row (idCita, as in the buttons I have which use a CommandArgument)... that way can use another class I have which would trigger a query that would edit a field called Estado....
However, I noticed that when I use CommandArguments, I use another void called...
protected void grdvEventosVendedor_RowCommand(object sender, GridViewCommandEventArgs e)
{
int intIdCita = int.Parse(e.CommandArgument.ToString());
if (e.CommandName == "Edicion")
{
//Some Code
}
else if (e.CommandName == "Borrar")
{
//More Code
}
else if (e.CommandName == "CRM")
{
//Even More Code
}
else if (e.CommandName == "VerMas")
{
//....
}
}
with this I can call both e.CommandName which tells me which button I pressed, and e.CommandArgument which is the value for idCita... however I noticed that the ddl void that I previously showed you doesnt have a GridViewCommandEventArgs e, instead it has a EventArgs e...
Is there a way that I can get the value of idCita from the gridview, all the way to the ddl void??
What do I need to add in the gridview code and in the cs file??
Thanks
Refactor you're code something like this - it should get you most of the way there, additionally look at converting the else if statements to a more readable switch case statement...
protected void dpdListEstado_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer);
MeaningfulNameHere(int.Parse(grdvEventosVendedor.DataKeys[gvr.RowIndex]),"Estado");
}
protected void grdvEventosVendedor_RowCommand(object sender, GridViewCommandEventArgs e)
{
MeaningfulNameHere(int.Parse(e.CommandArgument.ToString()),e.CommandName);
}
private void MeaningfulNameHere(int id, string commandName)
{
if (commandName == "Edicion")
{
//Some Code
}
else if (commandName == "Borrar")
{
//More Code
}
else if (commandName == "CRM")
{
//Even More Code
}
else if (commandName == "VerMas")
{
//....
}
else if (commandName == "Estado")
{
}
}
I have gridview which contains 60 rows and each row has 4 radiobutton option (select any one). To opearate that code , on submit button wrote code as follows . I didn't work.
My design view :
<asp:GridView ID="gvSurvey" runat="server" CellPadding = "4" OnRowDataBound ="gvSurvey_RowDataBound" BorderWidth ="2"
AutoGenerateColumns="False" EmptyDataText="No data Available" GridLines="None"
HorizontalAlign="Center" ForeColor="#333333" Font-Names="Verdana" ShowFooter="True">
<RowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="HEADER" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="QTN_NO" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="SQTN_NO" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField Visible="true" HeaderText ="Strongly Disagree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn1" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton1" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Agree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn2" runat ="server" GroupName ="MyRadioGroup"/>
<%--<asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton2" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Disagree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn3" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%--<input name="MyRadioButton3" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText ="Strongly Agree">
<ItemTemplate>
<asp:RadioButton ID="rdbtn4" runat ="server" GroupName ="MyRadioGroup"/>
<%-- <asp:CustomValidator ID="cvRadioButtonGroup" runat="server" ErrorMessage="* make a selection" onservervalidate="cvRadioButtonGroup_ServerValidate" /> --%>
<%-- <input name="MyRadioButton4" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
C#
for (i = 0; i < gvSurvey.Rows.Count; i++)
{
RadioButton rdbtn1 = (RadioButton)gvSurvey.Rows[i].Cells[3].FindControl("rdbtn1");
RadioButton rdbtn2 = (RadioButton)gvSurvey.Rows[i].Cells[4].FindControl("rdbtn2");
RadioButton rdbtn3 = (RadioButton)gvSurvey.Rows[i].Cells[5].FindControl("rdbtn3");
RadioButton rdbtn4 = (RadioButton)gvSurvey.Rows[i].Cells[6].FindControl("rdbtn4");
// RadioButton rdbtn1=(RadioButton) gvSurvey.Rows[i].ClientID
qtn_no = dtSurvey.Rows[i]["QTN_NO"].ToString();
sqtn_no = dtSurvey.Rows[i]["SQTN_NO"].ToString();
if (rdbtn1.Checked)
{
rdbtn1.Text = "1";
lblMsg.Text = nominationsBiz.SaveSuggestion(ticketNo.ToString(), qtn_no, sqtn_no, rdbtn1.Text);
}
Please Go through the following code you will find the Solutions
// It will be on your submit button click
protected void getPinCode()
{
foreach (GridViewRow grdRows in gvSurvey.Rows)
{
RadioButton rbt1 = (RadioButton)grdRows.FindControl("rdbtn1");
RadioButton rbt2 = (RadioButton)grdRows.FindControl("rdbtn2");
RadioButton rbt3 = (RadioButton)grdRows.FindControl("rdbtn3");
RadioButton rbt4 = (RadioButton)grdRows.FindControl("rdbtn4");
string Value = RadioValue(rbt1);
//Similarly you can do for all radio button
if(!string.IsNullOrEmpty(Value))
{
lblMsg.Text = nominationsBiz.SaveSuggestion(ticketNo.ToString(), qtn_no, sqtn_no, Value);
}
}
}
protected string RadioValue(RadioButton Rbtlst)
{
string Value = "";
if (Rbtlst.Checked == true)
{
Value = Rbtlst.Text;
}
return Value;
}