Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a datagridview with datagridviewcomboBox column and datagridviewTextbox column.the combobox column contains products and when i select a product, the product code should appear in textbox column from product table.I have already binded the data in combobox but not able to display data in textbox column.



how Can I do this.. Please Help
Posted

In Gridview RowCommand you have get the dropdown values as

DropDownList test= (DropDownList)e.Row.FindControl("DropDown1"); //Finding Dropdown control
string value = test.SelectedItem.Value;
TextBox test1= (TextBox)e.Row.FindControl("textbox1"); //Finding textbox control
string value1=test1.Text;
 
Share this answer
 
Comments
mjawadkhatri 24-Nov-14 6:24am    
Thanks you sir, but On which event I use this code?
[no name] 24-Nov-14 6:32am    
in side the Row Command event of the GridView.

and make sure you have make the AutoPostBack property of the dropdown =True
mjawadkhatri 24-Nov-14 6:45am    
I didn't find any Row Command event in datagridview,
Kindly help me sir
mjawadkhatri 24-Nov-14 6:50am    
I am using windows form application,
mjawadkhatri 24-Nov-14 6:45am    
I didn't find any Row Command event in datagridview,
Kindly help me sir
XML
<pre>Gridview Markup

<asp:TemplateField HeaderText="Address">
<EditItemTemplate><asp:TextBox ID="txtEAddress" Width="100px" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"     onselectedindexchanged="DropDownList1_SelectedIndexChanged"><asp:ListItem>4</asp:ListItem><asp:ListItem>3</asp:ListItem><asp:ListItem>2</asp:ListItem><asp:ListItem>1</asp:ListItem></asp:DropDownList></EditItemTemplate><ItemTemplate><asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>'></asp:Label></ItemTemplate><FooterTemplate><asp:TextBox ID="txtAddress" runat="server" Width="100px" TextMode="MultiLine"></asp:TextBox></FooterTemplate></asp:TemplateField>



Code Behind
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
   { 
        DropDownList ddl = (DropDownList)sender; 
        GridViewRow row = (GridViewRow)ddl.Parent.Parent; 
        int idx = row.RowIndex;
        TextBox txtECustCode = (TextBox)row.Cells[0].FindControl("txtECustCode"); 
       string _text1 = txtECustCode.Text.ToString();
    }
 
Share this answer
 
Comments
mjawadkhatri 24-Nov-14 7:05am    
I am using Windows From Application. Can I do this in Windows From Application?
For Windows Application

C#
private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;
    if (cb != null)
    {
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= new
        EventHandler(cb_SelectedIndexChanged);

        // now attach the event handler
        cb.SelectedIndexChanged += new
        EventHandler(cb_SelectedIndexChanged);
    }
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900